Tree Views

Tree views are used to present nested lists of data that form a hierarchy. A tree view's data is specified just like that of a list view, but any item in the tree data that is itself an instance of org.apache.pivot.collections.List will be treated as a branch in the tree, and the user will be able to expand the branch to see its children.

The following example shows a basic tree view. This example specifies the tree data as the contents of tree_data.bxml. For the purpose of this example, this data is static. A real application could load dynamic data and use a custom renderer to present the raw data straight to the user.

The BXML for this example is shown below:

            
            <Window title="Tree Views" maximized="true"
                xmlns:bxml="http://pivot.apache.org/bxml"
                xmlns="org.apache.pivot.wtk">
                <Border>
                    <ScrollPane horizontalScrollBarPolicy="fill_to_capacity">
                        <TreeView>
                            <treeData>
                                <bxml:include src="tree_data.bxml"/>
                            </treeData>
                        </TreeView>
                    </ScrollPane>
                </Border>
            </Window>
            
        

The BXML that defines the tree data is shown below.

            
            <TreeBranch xmlns="org.apache.pivot.wtk.content">
                <TreeBranch text="Activity" icon="/org/apache/pivot/tutorials/folder.png">
                    <TreeBranch text="Games" icon="/org/apache/pivot/tutorials/folder.png">
                        <TreeNode text="Foosball" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Ping Pong" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Air Hockey" icon="/org/apache/pivot/tutorials/page_white.png"/>
                    </TreeBranch>
                    <TreeBranch text="Sports" icon="/org/apache/pivot/tutorials/folder.png">
                        <TreeNode text="Baseball" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Basketball" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Football" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Ice Hockey" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Soccer" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Softball" icon="/org/apache/pivot/tutorials/page_white.png"/>
                    </TreeBranch>
                    <TreeNode text="Camping" icon="/org/apache/pivot/tutorials/page_white.png"/>
                    <TreeNode text="Skiing" icon="/org/apache/pivot/tutorials/page_white.png"/>
                </TreeBranch>
                <TreeBranch text="Occasion" icon="/org/apache/pivot/tutorials/folder.png">
                    <TreeBranch text="Holidays" icon="/org/apache/pivot/tutorials/folder.png">
                        <TreeNode text="Christmas" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Independence Day" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Labor Day" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="New Year's Day" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="President's Day" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Thanksgiving" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Valentine's Day" icon="/org/apache/pivot/tutorials/page_white.png"/>
                        <TreeNode text="Veteran's Day" icon="/org/apache/pivot/tutorials/page_white.png"/>
                    </TreeBranch>
                    <TreeNode text="Anniversary" icon="/org/apache/pivot/tutorials/page_white.png"/>
                    <TreeNode text="Birthday" icon="/org/apache/pivot/tutorials/page_white.png"/>
                    <TreeNode text="Wedding" icon="/org/apache/pivot/tutorials/page_white.png"/>
                </TreeBranch>
                <TreeBranch text="Location" icon="/org/apache/pivot/tutorials/folder.png">
                    <TreeNode text="Africa" icon="/org/apache/pivot/tutorials/folder.png"/>
                    <TreeNode text="Antarctica" icon="/org/apache/pivot/tutorials/folder.png"/>
                    <TreeNode text="Asia" icon="/org/apache/pivot/tutorials/folder.png"/>
                    <TreeNode text="Australia" icon="/org/apache/pivot/tutorials/folder.png"/>
                    <TreeNode text="Europe" icon="/org/apache/pivot/tutorials/folder.png"/>
                    <TreeNode text="North America" icon="/org/apache/pivot/tutorials/folder.png"/>
                    <TreeBranch text="South America" icon="/org/apache/pivot/tutorials/folder.png">
                        <TreeNode text="Peru" icon="/org/apache/pivot/tutorials/page_white.png"/>
                    </TreeBranch>
                </TreeBranch>
            </TreeBranch>
            
        

Since this example is written entirely in BXML, there is no associated Java source.

Next: File Browsing