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
editormax
Posts: 133
Registered: ‎07-20-2009
My Device: Not Specified
Accepted Solution

Anyway to know draw text 's width?

Dear all,

I am using the Graphics graphics to draw Text. Is it anyway to found out the width of the string to draw. Because i would like to draw another string after that string in the same horizontal Lilne. Thanks you 

New Developer
BekNazar
Posts: 14
Registered: ‎08-11-2009
My Device: Not Specified

Re: Anyway to know draw text 's width?

Get the Font and then:

defaultFont.getAdvance("My Text");

This returns an integer.

Developer
editormax
Posts: 133
Registered: ‎07-20-2009
My Device: Not Specified

Re: Anyway to know draw text 's width?

Oh thanks a lot!

Regular Visitor
MeshMS
Posts: 1
Registered: ‎06-22-2011
My Device: Tourch 9800

Re: Anyway to know draw text 's width?

This is very helpful, thank you!!

Contributor
jenicek
Posts: 10
Registered: ‎10-13-2011
My Device: 9900

Re: Anyway to know draw text 's width?

Great! Thanks!!!
Regular Contributor
galeb
Posts: 77
Registered: ‎11-03-2009
My Device: 9810 Torch

Re: Anyway to know draw text 's width?

Btw, if you are using different font than default font (lets say smallFont), you can also do this:

smallFont.getAdvance("My text here");

 :Online2long: