BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-22-2009, 09: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, 08: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, 04: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, 04: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, 04: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, 07: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, 08: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

HSS 12PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC FOR VINTAGE CAR, BIKES,JEEP
$163.99
HSS 12PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC FOR VINTAGE CAR, BIKES,JEEP pictureHSS 21PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC - VINTAGE CAR,BIKES, JEEP
$222.99
HSS 21PCS VALVE SEAT & FACE CUTTER 45DEC 30DEC 20DEC - VINTAGE CAR,BIKES, JEEP pictureVintage SIGNODE Crimping W14 Tool 17.5" long pat#1784123 dec9 1930 /N12167
$19.48
Vintage SIGNODE Crimping W14 Tool  17.5New in Box - Digital Dec RL01K-DC 5MB Data Cartridge - Vintage
$200.0
New in Box - Digital Dec RL01K-DC 5MB Data Cartridge - Vintage pictureVtg Chemistry Science Lab Beaker Stand Test Tube Bracket Clamp Industrial Dec
$15.0
Vtg Chemistry Science Lab Beaker Stand Test Tube Bracket Clamp Industrial Dec  picture






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