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

Posts: 10
Registered: ‎08-29-2012
My Device: 9860
My Carrier: Relience

How to set the field in Center

Hi all,

can any one give me the code for setting the field in center without ussing layout



Thanks, sahil

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

Re: How to set the field in Center

The short answer answer is "it depends".  The things it depends on are whether you want the Field to be in the center vertically and/or horizontally, and also the type of Field you wish to centralize.  And it can also depend on the type of Manager you are using.


For example, you can put a LabelField in the horizontal center of a VerticalFieldManager using the the style


but this does not work for an EditField.


Often the best way to achieve this is to add the Field to a Manager and use the Manager's sublayout() to get the Field in the correct place.

Posts: 434
Registered: ‎07-23-2012
My Device: Blackberry 10
My Carrier: Orange

Re: How to set the field in Center

Most of the time I have  use the following logic (HCENTER Only)


X= (Totalwidth-FieldWidth)>>1

Used setPositionChild inside the sublayout method

For example


Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.