BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-25-2008, 08:19 AM   #1 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom Button Component

Please Login to Remove!

Guys,

Here is another query, I am posting too many strange things today ..

well actually I am working on this custom button field with a small image on left side along with a string following it. What I am trying to do is to create a button with an image and user provided string.

Not the issue I am facing is that, here I have to use Graphics class FillRectangle method to create a rectangle that can accommodate both my image and the string provided. I am able to get the width of the image using getWidth method but for string I m not sure how to get the width in pixels as the String.length() method gives us the number of characters in the string.

I hope you understand the scenario, what I need is to have something that can give me the length of the string in pixels, so that I can draw that big rectangle to accommodate both my image and the string. Right now I am putting it hard coded but I want it to be custom enough to expand or shrink depending upon the given string.

Any idea how we can get that width in pixel for a string. I hope my English is able to make u understand the things.
__________________
Smart People ask for Help!!!
Offline  
Old 11-25-2008, 08:23 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

use getFont().getAdvance(your_string_var) to find out the length of the string using the Font set for your field
__________________
Blessed is the end user who expects nothing, for he/she will not be disappointed. (Franklin's Rule)
Offline  
Old 11-25-2008, 08:29 AM   #3 (permalink)
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Ivanov View Post
use getFont().getAdvance(your_string_var) to find out the length of the string using the Font set for your field
Hello Ivanov,

My good friend, good to see you back.

I can now post more queries...lol

it works wonder my friend.
__________________
Smart People ask for Help!!!
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.