BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-22-2009, 08:41 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2009
Model: 8350i
PIN: N/A
Carrier: telus
Posts: 40
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Labelfield, top of text being clipped off

Please Login to Remove!

I have a basic labelfield in which I override paint() in order to change background and text color. I also override layout() in order to set the height and width and I also set my desired font here. The field is 320x40 with a font set to 30. No matter what I seem to do the top of the text is clipped off. I've tried changing the size of the field with no luck. If I change the size of the font it stops clipping at around 26 and gets worse the larger it is. I've tried every damn setting in the labelfield constructor and can't seem to get this damn thing vertically centered. HELP (that's a cry for help)
Offline  
Old 11-23-2009, 07:49 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

You need to override getPreferredHeight() and set it to your font size + margin.
Offline  
Old 11-23-2009, 03:17 PM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2009
Model: 8350i
PIN: N/A
Carrier: telus
Posts: 40
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have getPreferredHeight() overridden and set to a height of 50. As I adjust that height it only seems to add below my font. Maybe I should include some code. I must have goofed up something.
Offline  
Old 11-23-2009, 03:18 PM   #4 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2009
Model: 8350i
PIN: N/A
Carrier: telus
Posts: 40
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

LabelField lf_answer = new LabelField("0", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.RIGHT | LabelField.USE_ALL_HEIGHT | LabelField.TOP)
{
protected void layout(int width, int height)
{
super.layout(320, 30);
setExtent(320, 30);
}

public int getPreferredWidth(){
return 320;
}

public int getPreferredHeight(){
return 30;
}

public void paint(Graphics graphics)
{

graphics.setBackgroundColor(Color.BLACK);
graphics.setColor(Color.WHITESMOKE);
FontFamily fontFamily[] = FontFamily.getFontFamilies();
Font _font = fontFamily[1].getFont(FontFamily.TRUE_TYPE_FONT, 24);
graphics.setFont(_font);
graphics.clear();
super.paint(graphics);
}
};
Offline  
Old 11-23-2009, 03:19 PM   #5 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2009
Model: 8350i
PIN: N/A
Carrier: telus
Posts: 40
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The code I included works because I've lowered the font size. But with the labelfield at 50 (what I want) and the font at anything over 28 it clips off the top.
Offline  
Old 11-23-2009, 06:04 PM   #6 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

A couple of observations:

1. don't create these fonts in your paint routine - this code is called (unneccessarily) each time the field is painted.

2. You need to draw the text yourself, in the position that makes sense. See graphics.drawText().

3. After you draw the text yourself, get rid of the super.paint()
Offline  
Old 11-23-2009, 07:18 PM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2009
Model: 8350i
PIN: N/A
Carrier: telus
Posts: 40
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

That worked like a charm, thanks.
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.