Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd
Accepted Solution

how to center the button on popup screen

look at the pic, i have created a popup screen on the menu key click and i have made that transparent and make it to the full screen and i have added four buttons vertically plz, can u correct me how can i center that button in the pop up screen.

here is my code

if (Keypad.key(keycode) == Keypad.KEY_MENU) 
              MysettingMenu mymenu = new MysettingMenu();
        	System.out.println("--------------Menu -key -Pressed-----------------");
 public class MysettingMenu extends PopupScreen{
		 public MysettingMenu(){
			 super(new VerticalFieldManager(), Screen.DEFAULT_CLOSE); 
			 this.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.WHITE, 80));
			 setBorder(BorderFactory.createSimpleBorder(new XYEdges(),Border.STYLE_TRANSPARENT));
             this.add(new ButtonField("Favourites"));
			 this.add(new ButtonField(" Settings "));
			 this.add(new ButtonField("  About    "));
			 this.add(new ButtonField("  Exit    "));
		protected void sublayout(int width, int height) {
			// TODO Auto-generated method stub
			 super.sublayout(Display.getWidth(), Display.getHeight());       
			  int leftMargin = (Display.getWidth() - width)/8;       
			  int topMargin = (Display.getHeight() - height)/8;   
			  setPosition(leftMargin, topMargin); 


Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to center the button on popup screen

[ Edited ]

There are a variety of ways this could be done, but in your case the easiest is allow the screen to only use as much space as it needs, and then position it centrally.



1) change this call

super.sublayout(Display.getWidth(), Display.getHeight());

to actually supply the same width and height that you were given.

2) remove this:


3) Change to margin settings so that they use the actual width and height and center based on this.  For example:

int leftMargin = (Display.getWidth() - this.getWidth())/2;


By the way, I strongly recommend that you never call super.layout(....) and then ignore the size it has given you and issue you own setExtent.  Unless you know what you are doing, this can cause Fields to display incorrectly.  If you think you need to set your own size, then I suggest you create your own manager and do the layout yourself.  More on doing this here: