Would you like to tell us how we are doing?

You bet No thanks

Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Choice field: tree field

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



Supported since

BlackBerry Java SDK 3.7

More information

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


This screen shows 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();       
    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);

    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);