How To - Create a custom field using attributes of other UI objects
2010-09-26 14:16
411 查看
How To - Create a custom field using attributes of other UI objects
Last Updated: 27 March 2009 |
Article Number: DB-00737 |
Summary
This 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 of other UI objects.The following example shows how to combine the
VerticalScrollManagersand
EditFieldsto create a new
TextObjectFielditem. 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 for our object
public TextBoxField(int width, int height) {
//This call to super will help keep the object in place
super(Manager.NO_VERTICAL_SCROLL);
managerWidth = width;
managerHeight = height;
//vfm will allow scrolling within the object
VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
editField = new EditField(){
public void paint(Graphics g) {
//This invalidation will 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 was made by the system then
//both parameters would be 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 will force the height of the object
//where the above super.sublayout() call will
//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相关文章推荐
- 改进:How To - Create a custom field using attributes of other UI objects
- Change language of UI using custom control in SharePoint 2010
- How to: Create Custom Configuration Sections Using ConfigurationSection
- Using Custom Attributes in HTML5
- Create custom field type
- 保存自定义对象的数组 save and restore an array of custom objects
- A Data Access Layer to persist business objects using attributes and reflection - Part I
- Advanced Pricing - How to source Pricing Attributes using QP_CUSTOM_SOURCE.Get_Custom_Attribute_Valu
- Using a Custom Action to Create a Database During Installation
- create Mailboxes using addresses other than the default
- Example Source Code: Using Face Detection To Create The Illusion Of Real 3D On iOS Devices
- Siebel Tools: Create Custom MiniButton Using Tools
- [tmux] Create collections of panes using tmux windows
- Breaking Tight Coupling by using Mock Objects(Chapter 4 of Python Testing Beginner's Guide)
- The basics of using ui-router with AngularJS
- Create a Simple Custom Action Using Visual Studio 2010
- Advanced Pricing - How to source Pricing Attributes using QP_CUSTOM_SOURCE.Get_Custom_Attribute_Valu
- Using CustomProperties of CodeSmith
- Using a Custom Action to Create a Database During Installation
- Siebel Tools: Create Custom MiniButton Using Tools