I want to make custom control which consists of a LabelField and Textbox. How can i make a custom control using jde开发者_高级运维 as IDE for blackberry.
Thanks in advance.
In Blackberry you can create a custom component by extending from Field
public class MyField extends Field {
public void layout(int width, int height){
setExtent( width, height ); //set the field size
}
public void pain(Graphics g){
//do your own paint here
//g.drawText ("Test", 0, 0 );
}
}
in case you want to create consist of a LabelField and TextField, I suggest you extend from TextField
public class InputField extends TextField {
private String _label;
private TextField _text;
public InputField(String label){
_label = label;
}
public void layout(int width, int height ){
setExtend( width + 200, height ); //just an example, i add 200 pixel for width
//you can get the width of the _label too
//need other functions to get width based on the String
}
//you override how to paint in screen
public void paint(Graphics g){
super.paint(g);
g.drawText (getLeft()-200, getTop(), _label);
}
}
See more examples here http://supportforums.blackberry.com/t5/Java-Development/Custom-Control/td-p/159699
精彩评论