Welcome!

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

Reply
New Contributor
Kvest
Posts: 3
Registered: ‎11-13-2010
My Device: Not Specified
Accepted Solution

Problem with placing components in the center

I have MainScreen or FullScreen and four ButtonField. How can I put buttons to this container in the center(vertically and horizontally)?

I try to use flag Field.FIELD_HCENTER | ButtonField.HCENTER | Field.FIELD_VCENTER | ButtonField.VCENTER for buttons, but they take only horizontal center

Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Problem with placing components in the center

the layout managers are limited in their options.

you can create a custom layout (it is easier than it looks, give it a try):

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
TJBeanz
Posts: 39
Registered: ‎06-22-2009
My Device: Torch (9800), Bold (9930)
My Carrier: Verizon

Re: Problem with placing components in the center

I've struggled with this before as well.  Here's what I've found to work for centering a single item:

 

VerticalFieldManager vfm = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH | VerticalFieldManager.NO_HORIZONTAL_SCROLL | VerticalFieldManager.NO_VERTICAL_SCROLL);

// Create a horizontally centered HFM
HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_HEIGHT | HorizontalFieldManager.NO_HORIZONTAL_SCROLL | HorizontalFieldManager.NO_VERTICAL_SCROLL | HorizontalFieldManager.FIELD_HCENTER);

// Create a vertically centered label
LabelField label = new LabelField("Test", LabelField.FIELD_VCENTER);
hfm.add(label);

vfm.add(hfm);
add(vfm);

 

You should be able to extend this to do what you're looking to do with another VerticalFieldManager.

 

-T

----------------------------------------------------------------------------------
Click "Accept as Solution" if this post was what you needed.
Give kudos by clicking on the star icon to say "Thanks!" if you feel this response is helpful.
Please use plain text.
New Contributor
Kvest
Posts: 3
Registered: ‎11-13-2010
My Device: Not Specified

Re: Problem with placing components in the center

Great solution,TJBeanz. Thank you very much! 

 

Please use plain text.