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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
rgelb1
Posts: 108
Registered: ‎08-05-2008
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.

Please use plain text.
Administrator
MSohm
Posts: 13,065
Registered: ‎07-09-2008
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.
Found a bug? Report it using the Issue Tracker
Please use plain text.
Developer
rgelb1
Posts: 108
Registered: ‎08-05-2008

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.
Please use plain text.
Developer
peter_strange
Posts: 17,952
Registered: ‎07-14-2008

Re: Centering text in the LabelField

Try this:

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

Please use plain text.
Developer
Developer
bo
Posts: 167
Registered: ‎11-12-2008

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