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 http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://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.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

6 Responses to Setting word wrapping on a Spark List control in Flex 4

  1. Doug says:

    Dang… yet another winner! Thanks! Gotta love the Flex “nuggets!”

  2. J says:

    That’s crap, this doesn’t work.

  3. Tom says:

    I’m also finding the word wrap isn’t working in Flex 4.5. Does anybody have a solution?

  4. marlon says:

    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. :)

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree