The following example shows you how you can create a Tree control in Flex with variable row heights by setting the variableRowHeight and wordWrap properties.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/11/29/creating-a-flex-tree-control-with-variable-row-heights/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:XML id="xmlDP">
        <root>
            <para label="Paragraph 1">
                <node label="Lorem ipsum dolor sit amet, consectetuer adipiscing elit." />
                <node label="Cras porttitor nunc a pede." />
                <node label="Nulla ac magna non risus accumsan egestas." />
                <node label="Aenean pretium porta felis." />
                <node label="Sed massa." />
            </para>
            <para label="Paragraph 2">
                <node label="Pellentesque pretium eros id odio tincidunt lobortis." />
                <node label="Praesent vitae dolor eget nisl adipiscing pretium." />
                <node label="Fusce nonummy dignissim risus." />
                <node label="Nunc sodales, lectus vitae nonummy cursus, augue lectus auctor orci, vel aliquet enim neque vel eros." />
                <node label="Donec laoreet euismod libero." />
                <node label="Etiam ut lectus." />
            </para>
            <para label="Paragraph 3">
                <node label="Maecenas ut nibh eu diam viverra suscipit." />
                <node label="Pellentesque auctor, turpis vel lobortis suscipit, neque tortor tristique nibh, venenatis suscipit nisl nisl eget magna." />
                <node label="Donec interdum." />
                <node label="Praesent diam." />
            </para>
            <para label="Paragraph 4">
                <node label="Proin nulla." />
                <node label="Morbi tincidunt, sapien in sollicitudin venenatis, nibh tortor pretium ante, non pharetra urna dolor et libero." />
                <node label="In malesuada risus at neque." />
            </para>
        </root>
    </mx:XML>

    <mx:Tree id="tree"
            dataProvider="{xmlDP}"
            labelField="@label"
            showRoot="false"
            variableRowHeight="true"
            wordWrap="true"
            alternatingItemColors="[#FFFFFF,#EEEEEE]"
            showScrollTips="true"
            width="300"
            rowCount="6" />

</mx:Application>

View source is enabled in the following example.

 
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.

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