how t开发者_StackOverflow社区o set the position of a button in java blackberry.
You can position a button or any other component on a screen by creating a Manager
class and overriding the sublayout() method. A Manager
is kind of like a Panel
in java i.e an area of the screen you can add components to. In the sublayout() method you should
set the size of the component with layoutChild()
set the position of the component with setPositionChild()
Set the overall size of the Manager with setExtent()
something like
button = new ButtonField();
HorizontalFieldManager manager = new HorizontalFieldManager(){
protected void sublayout(int width, int height) {
int buttonWidth = button.getPreferredWidth();
int buttonHeight = button.getPreferredHeight();
layoutChild(button,buttonWidth, buttonHeight);
setPositionChild(button, 0, 0);
setExtent(width, height);
}
};
manager.add(button);
You can override getPreferredWidth() and getPreferredHeight() for your button if you want to specify a certain width and height.
See
Custom layout Manager
Manager class
精彩评论