Setting word wrapping on a Spark List control in Flex 4

The following example shows how you can enable word wrapping on a Spark List control in Flex 4 by overriding the default layout with a VerticalLayout object and set its horizontalAlign property to “justify” (instead of the default “contentJustify”).

Full code after the jump.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/10/27/setting-word-wrapping-on-a-spark-list-control-in-flex-4/ -->
<s:Application name="Spark_List_layout_horizontalAlign_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/halo">
 
    <s:List id="lst"
            alternatingItemColors="[#DFDFDF,#EEEEEE]"
            useVirtualLayout="false"
            width="200"
            horizontalCenter="0" verticalCenter="0">
        <s:layout>
            <s:VerticalLayout gap="0" horizontalAlign="justify" />
        </s:layout>
        <s:dataProvider>
            <s:ArrayList>
                <fx:Object label="Lorem ipsum dolor sit amet, consectetur adipiscing elit." />
                <fx:Object label="Fusce pulvinar nisi ac leo rhoncus nec malesuada arcu accumsan." />
                <fx:Object label="Sed at metus eu mauris malesuada ornare." />
                <fx:Object label="Vestibulum et ante non arcu facilisis sagittis." />
                <fx:Object label="Praesent euismod bibendum tortor, pharetra pharetra nibh ultricies convallis." />
                <fx:Object label="Sed at mi quis urna lobortis mattis." />
                <fx:Object label="Nulla aliquet ante nec nisi auctor et pharetra leo blandit." />
            </s:ArrayList>
        </s:dataProvider>
    </s:List>
 
</s:Application>

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

6 thoughts on “Setting word wrapping on a Spark List control in Flex 4

      1. I tested in 4.5.1 and it doesn’t work. :( I’ve been scouring the web trying to figure this out and nothing works so far!

  1. mmm, in Flex 4.5.X, you must implement a custom item renderer for a (spark) list. specifically, use a label (o a textarea if you like so) inside the item renderer, and set its width to 80% (for example). if you use a icon for the item for render, use label width for adjusting.

    hope thie helps. :)

Comments are closed.