How to-create a custom field using attributes of the other UI objects
Last updated:27 March 2009 |
Article number:db-00737 |
Summary
This is article applies to the Following:blackberry®smartphones based on Java®technology Details
Using Java Technology, you can create a custom field that has a tailored behavior by combining and changing the elements O F Other UI objects.
The following example shows to combine the verticalscrollmanagers and editfields to create a new Textobjectfield item. The newly created item is a hybrid of the two items used to create it, allowing for a-text box with dimensions set in its Constructor-a Fixed width and vertical scrolling.
/*
* Textboxfield.java
*/
Extend Verticalfieldmanager to help control scrolling and
To set a fixed width/height for our field
public class TextBoxField extends Verticalfieldmanager {
Define Some variables to be used
In the class
private int managerwidth;
private int managerheight;
Private EditField EditField;
Pass in the fixed height and width of our object
public TextBoxField (int width, int height) {
This call to super would help keep the object
Super (Manager.no_vertical_scroll);
Managerwidth = width;
Managerheight = height;
VFM'll allow scrolling within the object
Verticalfieldmanager VFM = new Verticalfieldmanager (manager.vertical_scroll);
EditField = new EditField () {
public void Paint (Graphics g) {
This invalidation'll help keep the border clean
While scrolling
GetManager (). invalidate ();
Super.paint (g);
}
};
Vfm.add (EditField);
Add (VFM);
}
public void Paint (Graphics g) {
Super.paint (g);
Draw a rectangle around out TextBoxField
G.drawrect (0, 0, getwidth (), getheight ());
}
If This call to Sublayout is made by the system then
Both parameters would is passed with a value of 0.
This check and adjustment keeps the fixed properties
Maintained.
public void sublayout (int width, int height) {
if (Managerwidth = = 0) {
Managerwidth = width;
}
if (Managerheight = = 0) {
Managerheight = height;
}
Super.sublayout (Managerwidth, managerheight);
Force the extent of our manager.
This is force the height of the object
Where the above super.sublayout () call to
Set the width.
SetExtent (Managerwidth,managerheight);
}
The following two methods allows users of the
Textboffield Read and set its contents.
Public String GetText () {
return Editfield.gettext ();
}
public void SetText (String text) {
Editfield.settext (text);
}
}Keywords
Custom field, field, interface, Verticalfieldmanager, TextField, TextBox