How to-create a custom field using attributes of the other UI objects

Source: Internet
Author: User
Tags gettext

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.