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
Contributor
sahil143
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

Please use plain text.
Developer
peter_strange
Posts: 19,598
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

Field.FIELD_HCENTER

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.

Please use plain text.
Developer
kamal_nigam
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

setPositionChild(field,x,y)

Thanks
-------------------------------------------------------------------------------------
Press the Accept as solution Button when u got the Solution
Press Kudo to say thank to developer.
-------------------------------------------------------------------------------------.
Please use plain text.