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
spring_suvarna
Posts: 330
Registered: ‎02-25-2009
My Device: Not Specified

Centered Text in Fixed length LabelField

Hello,

 

i want to have LabelField of width Display.getWidth() -100.

 

if i keep width as Display.getWidth() then its working fine but when i decrease its width the text is getting cropped.

 

any solutio for this?

 

Thanks in advance

Please use plain text.
New Developer
virbahadur
Posts: 20
Registered: ‎09-24-2008
My Device: 9000, 8310, 8520, 9700, 9800, 9500

Re: Centered Text in Fixed length LabelField

create the LabelField with Field.FIELD_HCENTER style.
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Centered Text in Fixed length LabelField

You can try something like:

----------------------------------------

Calculate the label text length. If the length is greater than width then decrease the text font untils it fits in the reduced width.

For calculation text length you can use:

 

public static int getStringLength(String str) { Font font = Font.getDefault(); return font.getAdvance(str); }

 

Regards

Bikas 

 

Please use plain text.