|
|
Last Updated: 27 March 2009
|
Article Number: DB-00737
|
|
Summary
This article applies to the following:
|
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 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 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
分享到:
相关推荐
JavaEE源代码 commons-attributes-apiJavaEE源代码 commons-attributes-apiJavaEE源代码 commons-attributes-apiJavaEE源代码 commons-attributes-apiJavaEE源代码 commons-attributes-apiJavaEE源代码 commons-...
无服务器认知添加自定义属性此插件使您可以从无服务器向现有CloudFormation管理的...要求节点8+ 无服务器1+用法安装npm i serverless-cognito-add-custom-attributes ,然后将serverless-cognito-add-custom-attribu
This book will help you construct a great UI for your apps by teaching you how to create custom Android views. You will start by creating your first Android custom view and go through the design ...
commons-attributes-compiler-2.2.zipcommons-attributes-compiler-2.2.zipcommons-attributes-compiler-2.2.zipcommons-attributes-compiler-2.2.zipcommons-attributes-compiler-2.2.zip
Characterization of polarization attributes of seismic waves using continuous wavelet transforms
Which of the following SQL statements can be used to create a relational table? (a) INSERT (b) ADD (c) CREATE (d) APPEND Correct answer is (c) Your score on this question is: 10.00 ...
Learn Mobile Game Development in One Day Using Gamesalad is for anyone who wants to learn how to create their own video games for desktop and mobile devices. While this is an introductory book that ...
commons-attributes-2.2.zipcommons-attributes-2.2.zipcommons-attributes-2.2.zipcommons-attributes-2.2.zipcommons-attributes-2.2.zipcommons-attributes-2.2.zip
A well-designed custom view is much like any other well-designed class. It encapsulates a ... This lesson discusses how to use the Android framework to create the core functionality of a view class.
Jointly Learning Binary Code for Large-scale Face Image Retrieval and Attributes Prediction
ISO-TR 8550-2:2007 Guidance on the selection and usage of acceptance sampling systems for inspection of discrete items in lots - Part 2:Sampling by attributes - 完整英文版(19页).pdf
JavaEE源代码 commons-attributes-compilerJavaEE源代码 commons-attributes-compilerJavaEE源代码 commons-attributes-compilerJavaEE源代码 commons-attributes-compilerJavaEE源代码 commons-attributes-...
In this opening chapter you’ll learn how to create and configure your Laravel project using your existing PHP development environment, a virtual machine known as Laravel Homestead, and a minimal ...
babel-plugin-hoist-constant-jsx-attributes-源码.rar
ISO 2859-1_5 Series - Sampling procedures for inspection by attributes - 包含全部6份最新英文标准文件.7z
Inferring the social context in a given visual scene not only involves recognizing objects, but also demands a more indepth understanding of the relationships and attributes of the people involved....
If you are an iOS developer who has a basic idea of object-oriented programming and want to incorporate its concepts with Swift to optimize your application's code and create reusable and easily to ...
最重要的自定义属性插件 维护者: 联合维护者: 此插件将自定义属性添加到您的Mattermost实例中的用户。 您可以指定一个属性,然后指定将在其公共资料上显示该属性的特定用户,团队或组-这样其他用户可以轻松地...
org-gephi-data-attributes-api可视化软件gephi的插件,nbm格式,
commons-attributes-api-2.2.zipcommons-attributes-api-2.2.zipcommons-attributes-api-2.2.zipcommons-attributes-api-2.2.zipcommons-attributes-api-2.2.zipcommons-attributes-api-2.2.zip