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
Developer
Posts: 100
Registered: ‎01-13-2011
My Device: Not Specified
Accepted Solution

Horizontal and vertical centered group of field

Hello,

 

I have a screen form with two editFields and a button. What I want to do is to make them appears one under the other in the middle of the screen, like in this picture:

 

Dibujo.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I tryed using 3 HorizontalFieldManager with 

Manager.

FIELD_VCENTER.  inside a VerticalFieldManager created with Manager.USE_ALL_WIDTH style, but the fields appears on the top of the screen and they take all the width of the screen.

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Horizontal and vertical centered group of field

Since the main manager of your screen is VerticalFieldManager (you are using MainScreen, aren't you?), it will (understandably) ignore child fields' FIELD_VCENTER flags. It will, however, honor any horizontal alignment flags such as FIELD_HCENTER. However, FIELD_HCENTER does not play well with USE_ALL_WIDTH, so drop the latter. HorizontalFieldManager does honor its children's FIELD_VCENTER - you will have to use it to leverage this fact.

 

 

This might sound a little complicated at first, so I'll give you some more details:

1) Create your MainScreen with the explicit NO_VERTICAL_SCROLL style bit (important!)

2) Add a HorizontalFieldManager(USE_ALL_WIDTH | USE_ALL_HEIGHT) to the screen - let's call is bigHFM

3) Add a VerticalFieldManager(USE_ALL_WIDTH | FIELD_VCENTER) to bigHFM - let's call this new manager bigVFM

4) Create a HorizontalFieldManager(FIELD_HCENTER) - let's call it firstRow - and add it to bigVFM

5) Similarly, create a HorizontalFieldManager(FIELD_HCENTER) called secondRow and add it to bigVFM

6) Add LabelField("Label 1") and an edit field to firstRow

7) Add LabelField("Label 2") and another edit field to secondRow

8) Create a ButtonField("Button", FIELD_HCENTER) and add it to bigVFM

9) Run the application, look at the screen, tweak field margins if you feel like it and enjoy!

 

P.S.: albeit Field.setMargin is documented only in 6.0, it's been working like that since at least 4.2.0

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 100
Registered: ‎01-13-2011
My Device: Not Specified

Re: Horizontal and vertical centered group of field

Thanks for your answer, I made everything you told and now the fields are all vertically centered but labels don't appear and editFields takes all the width of the screen, how can I  solve this?

Highlighted
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Horizontal and vertical centered group of field

[ Edited ]

1) Are you adding labels before edit fields? It is important!

2) edit fields will indeed grab all width if left unchecked. I've already shown how to keep them contained in the following post - please take a look:

editfield and checkboxfield on same line

 

Post here is you still have problems.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!