Help Center
Local Navigation
- Creating a UI that is consistent with standard BlackBerry UIs
- BlackBerry device user input and navigation
- Screens
- Accelerometer
- Events
- Arranging UI components
-
UI components
- Add a UI component to a screen
- Aligning a field to a line of text
- Autocomplete text field
- Buttons
- Check boxes
- Create a bitmap
- Create a custom field
- Creating a field to display web content
- Dialog boxes
- Drop-down lists
- Labels
- Lists
- Option buttons
- Progress indicators
- Picker dialog boxes
- Search fields
- Spin boxes
- Text fields
- Tree views
- Menu items
- Custom fonts
- Spelling checker
- Related resources
- Glossary
- Provide feedback
- Document revision history
- Legal notice
BlackBerry Manuals & Help
>
Developer Documentation
>
Java Development Guides and API Reference
>
Development Guide
UI and Navigation - BlackBerry Java Application - 5.0
Create a field to display a tree view
Use a tree view to
display objects, such as a folder structure, in a hierarchical manner. A
TreeField contains nodes. The highest node is the root
node. A node in the tree can have child nodes under it. A node that has a child
is a parent node.
-
Import the required classes and interfaces.
import net.rim.device.api.ui.component.TreeField; import net.rim.device.api.ui.component.TreeFieldCallback; import net.rim.device.api.ui.container.MainScreen; import java.lang.String;
- Implement the TreeFieldCallback interface.
-
Invoke
TreeField.setExpanded() on the
TreeField object to specify whether a folder is
collapsible. Create a
TreeField object and multiple child nodes to the
TreeField object. Invoke
TreeField.setExpanded() using
node4 as a parameter to collapse the folder.
String fieldOne = new String("Main folder"); ... 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); ... int node10 = myTree.addChildNode(node1, fieldTen); myTree.setExpanded(node4, false); ... mainScreen.add(myTree); -
To repaint a
TreeField when a node changes, create a class that
implements the
TreeFieldCallback interface and implement the
TreeFieldCallback.drawTreeItem method. The
TreeFieldCallback.drawTreeItem method uses the
cookie for a tree node to draw a
String in the location of a node. The
TreeFieldCallback.drawTreeItem method invokes
Graphics.drawText() to draw the
String.
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:
Menu items
Previous topic: Best practice: Implementing tree views