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: 108
Registered: ‎08-05-2008
My Device: Not Specified
Accepted Solution

Centering text in the LabelField

I want to center the text in a label.  The label takes up all the width of the screen, but the text inside it won't center.

 

LabelField lbl = new LabelField("center this", LabelField.USE_ALL_WIDTH | LabelField.FIELD_HCENTER);

 

Am I missing something massively simple?

Thanks.

BlackBerry Development Advisor
Posts: 15,727
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Centering text in the LabelField

Please ensure that the manager the field has been added to is also using the USE_ALL_WIDTH style.  Otherwise it could be restricting the field's width.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 108
Registered: ‎08-05-2008
My Device: Not Specified

Re: Centering text in the LabelField

I am just adding it to the form itself (e.g. which inherits from MainScreen).  I assume that's using USE_ALL_WIDTH since all other elements on the screen take up full width.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Centering text in the LabelField

Try this:

LabelField lbl = new LabelField("center this", LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER);

Highlighted
Developer
Developer
Posts: 167
Registered: ‎11-12-2008
My Device: Not Specified

Re: Centering text in the LabelField

Note that if you don't use USE_ALL_WIDTH the label could be cut off.  Just spent hours trying to figure out why the label was being cropped and that was the reason!