Add A Ui Component To A Screen; Create A Custom Field - Blackberry JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE Manual

Version: 4.7.0
Hide thumbs Also See for JAVA DEVELOPMENT ENVIRONMENT - - DEVELOPMENT GUIDE:
Table of Contents

Advertisement

Development Guide
5.
To repaint a TreeField when a node changes, create a class that implements the TreeFieldCallback interface
and implement the TreeFieldCallback.drawTreeItem method. In the following code sample, 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);
}
}

Add a UI component to a screen

1.
Import the following classes:
• net.rim.device.api.ui.component.CheckboxField
• net.rim.device.api.ui.container.MainScreen
2.
Create an instance of a UI component.
CheckboxField myCheckbox = new CheckboxField("First checkbox", true);
3.
Add the UI component to your extension of a Screen class.
mainScreen.add(myCheckbox);

Create a custom field

You can only add custom context menu items and custom layouts to a custom field.
1.
Import the following classes:
• net.rim.device.api.ui.Field
• java.lang.String
• net.rim.device.api.ui.Font
• java.lang.Math
• net.rim.device.api.ui.Graphics
2.
Import the net.rim.device.api.ui.DrawStyle interface.
3.
Extend the Field class, or one of its subclasses, implementing the DrawStyle interface to specify the characteristics
of the custom field and turn on drawing styles.
public class CustomButtonField extends Field implements DrawStyle {
public static final int RECTANGLE = 1;
public static final int TRIANGLE = 2;
public static final int OCTAGON = 3;
UI components
23

Advertisement

Table of Contents
loading

This manual is also suitable for:

Java development environment

Table of Contents