Tree field

Use a tree field to display components in a hierarchical structure. You can configure tree field nodes to be collapsible.

Class TreeField
Supported since BlackBerry® Java® SDK 3.7
Example This screen shows a tree field.

For more information about tree fields, see the UI Guidelines.

Code sample: Creating a tree field

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

public class TreefieldDemo extends UiApplication
{
    public static void main(String[] args)
    {
        TreefieldDemo theApp = new TreefieldDemo();       
        theApp.enterEventDispatcher();
    }
    
    public TreefieldDemo()
    {        
        pushScreen(new TreefieldDemoScreen());
    }       
}

class TreefieldDemoScreen extends MainScreen
{
    public TreefieldDemoScreen()
    {             
        setTitle("Tree Field Demo");
        
        String fieldOne =  new String("Parent folder 1");
        String fieldTwo =  new String("Parent folder 2");
        String fieldThree =  new String("Sub-folder 1");
        String fieldFour =  new String("Sub-folder 2");
        
        TreeCallback myCallback = new TreeCallback();
        TreeField myTree = new TreeField(myCallback, Field.FOCUSABLE);
        
        int node1 = myTree.addChildNode(0, fieldOne);
        int node2 = myTree.addChildNode(0, fieldTwo);
        int node3 = myTree.addChildNode(node2, fieldThree);
        int node4 = myTree.addChildNode(node3, fieldFour);
       
        myTree.setExpanded(node4, false);
        
        add(myTree);

    }
    
    private class TreeCallback implements TreeFieldCallback 
    {
        public void drawTreeItem(TreeField _tree, Graphics g, int node, int y, int width, int indent) 
        {
            String text = (String)_tree.getCookie(node); 
            g.drawText(text, indent, y);
        }
    }
}
Next topic: Buttons
Previous topic: Location picker

Was this information helpful? Send us your comments.