BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-25-2008, 07: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, 07: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, 07: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  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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