Reputation: 841
I am developing a bb application for which i want to center a button. I am not using a custom field manager. Below is some of my code:
ButtonField button;
button=new ButtonField( "Go!" );
add(button);
I will like this button to be centered on the screen. Need help. Thanks
I tried that Paul...it did not work...here is my code for the mainscreen:
class Vfmdemo extends UiApplication {
// main method
public static void main(String[] args) {
Vfmdemo theApp = new Vfmdemo();
UiApplication.getUiApplication().pushScreen(new VFMScreen());
theApp.enterEventDispatcher();
}
}
// VFM
class VFMScreen extends MainScreen {
public VFMScreen(){
// create a manager and allow scrolling when lots of fields are added
VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
// add a label
vfm.add(new LabelField("VerticalFieldManager..."));
// add another label
vfm.add(new LabelField("default horizontal alignment is left"));
// add another label that takes up full screen width
vfm.add(new LabelField("using all width & long label...",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH));
// add another label that takes centered horizontally
vfm.add(new LabelField("horizontally centered...",
Field.FIELD_HCENTER));
vfm.add(new ButtonField("Go!!",Field.FIELD_HCENTER));
// add vfm to screen
add(vfm);
}
Upvotes: 2
Views: 2039
Reputation: 1052
You will need to use a pair of managers like this:
// Center a field on the screen using managers
HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT);
VerticalFieldManager vfm = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_VCENTER);
vfm.add(new ButtonField("Go!", FIELD_HCENTER));
hfm.add(vfm);
add(hfm);
Upvotes: 1