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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified
Accepted Solution

Center a HorizontalFieldManager vertically on the screen

Hi everyone,


I have a HorizontalFieldManager within a VerticalFieldManager. The HorizontalFieldManager contains a BitmapField in one "cell", and a Custom GridFieldManager in another cell.


I'm trying to make it so that the HorizontalFieldManager is vertically centered on the screen, but have been unable to do so. Most of the forum posts say to "create your own manager". I can do that, however I am unsure what the Manager would need to specify in order to vertically center the HorizontalFieldManager.


Can anyone push me in the right direction? Here is what I have so far:



imageOutputField = new BitmapField();
href = new HrefField("Synopsis", 0xffffff, 0x043184, 0x00EF3825);


VerticalFieldManager vfm = new VerticalFieldManager(
 	| VerticalFieldManager.VERTICAL_SCROLL
	| VerticalFieldManager.VERTICAL_SCROLLBAR);

horiz = new HorizontalFieldManager(DrawStyle.VCENTER);


synchronized (UiApplication.getEventLock()) {



Posts: 74
Registered: ‎01-03-2010
My Device: Not Specified

Re: Center a HorizontalFieldManager vertically on the screen

drawstyle.VCENTER may be for text positioning,  try Field.FIELD_VCENTER

Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: Center a HorizontalFieldManager vertically on the screen

Hi Jack,


I tried out your suggestion, and I am still receiving the same response. Does anyone have any other ideas? Thanks!

Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Center a HorizontalFieldManager vertically on the screen

This works for me:


public class TestScreen extends MainScreen {
    public TestScreen() {
        HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_HEIGHT);
        LabelField lf = new LabelField("Sample Text", FIELD_VCENTER);


The key to using FIELD_VCENTER is to make sure that the parent HorizontalFieldManager is the right height. You have to be careful, especially when using USE_ALL_HEIGHT, that it doesn't get bigger than. That's why I turned off vertical scrolling for the screen. (Otherwise the text will end up centered many thousands of pixels below the screen.) As an alternative, you could subclass HorizontalFieldManager and return a preferred height of the screen height (perhaps minus a header).

Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Posts: 22
Registered: ‎04-09-2010
My Device: Storm
My Carrier: Just developing

Re: Center a HorizontalFieldManager vertically on the screen

[ Edited ]

Here's another way:



Bikas wrote:


HorizontalFieldManager hfm = new HorizontalFieldManager();    
        LabelField testLabel1 = new LabelField( "Test Label1");    
        LabelField testLabel2 = new LabelField( "Test Label2");
        int leftEmptySpace = (Display.getWidth() - hfm.getPreferredWidth()) / 2;
        int topEmptySpace = (Display.getHeight() - hfm.getPreferredHeight()) / 2;
        hfm.setMargin(topEmptySpace, 0, 0, leftEmptySpace);


Worked perfectly. In my opinion it is better this way. You create what you want inside a manager, then add the manager and after that do the math (with getPreferredWidth/height) and set the Margins.