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
Posts: 75
Registered: ‎01-28-2009
My Device: Not Specified
Accepted Solution

set font size, not in pixels

Hi,

 

How can I set the font size to a system font size. For example, if I wanted to set the font to the same size as it appears when you set the size to 10 under the Options screen.

 

Thanks.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: set font size, not in pixels

Font.getDefaultFont() will return you the System default Font, if you haven't set a Default FOnt for the Application.  You can get the Size from that.  Is that what you wanted?
Developer
Posts: 75
Registered: ‎01-28-2009
My Device: Not Specified

Re: set font size, not in pixels

Not quite, unless from Font.getDefault() I can get the size (again, not in pixels).

 

I want to allow the user to select the font size for use within my program:

 

ie: 7,8,9,10... or System font size

 

And since the screen resolution is different for various devices, I can't just set the height using the setHeight(int pixels) method, since a size 10 on one device will require a different height than a size 10 on another device.

 

I'd like for my font heights (7,8,9, etc) to match up with the devices...

 

THanks!

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: set font size, not in pixels

Can you factor the font height using Display.getVerticalResolution() to work out the size?
Developer
Posts: 75
Registered: ‎01-28-2009
My Device: Not Specified

Re: set font size, not in pixels

That's what I was thinking, though if I could somehow get the font size to match up with the default ones used by the system, that would be ideal.
Developer
Posts: 75
Registered: ‎01-28-2009
My Device: Not Specified

Re: set font size, not in pixels

FYI:

 

FOund it:

 

public Font derive(int style,
int height,
int units)

Set units to Ui.UNITS_pt, then specify the size with the height variable

New Developer
Posts: 54
Registered: ‎11-12-2008
My Device: Bold 9800 or Storm 3 whichever hits Verizon first.
My Carrier: Verizon

Re: set font size, not in pixels

[ Edited ]

Okay so i have just spent the past 2 hours googling and searching including this forum on a simple example on how to set the font size for a handheld application and ran across this forum posting several times. I am not clear on how to implement the Font on the handheld.

Could you clarify exactly how to use the Font.derive please.
I tried the following but eclipse is yelling at me.

Font f = new Font();
Font.derive(Font.PLAIN, 10, Ui.UNITS_pt);
super.getActiveScreen().setFont(f);

 

Current time is 3:55pm EST. I am online for chat at PowerMountain Chat just enter in any user name to connect or post response to this forum please.

Message Edited by black_berry on 03-24-2009 03:55 PM
Thank you all for your support
black_berry
BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: set font size, not in pixels

The Font class does not have a constructor.  You can use the static Font.getDefaultFont method to obtain the default font.  You can then call the derive method on the Font object returned from this method.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 11
Registered: ‎04-15-2009
My Device: Not Specified

Re: set font size, not in pixels

Hey, just in case someone else is wondering, here is the solution:

 

// First, derive the default font and modify it to be PLAIN and 10 pt

Font myFont = Font.getDefault().derive(Font.PLAIN, 10);

 

// Then, set the font to what you derived above

graphics.setFont(myFont );


// Then draw the text

graphics.drawText("Hello World", xpos, ypos);

Contributor
Posts: 14
Registered: ‎07-02-2012
My Device: BlackBerry 9930
My Carrier: BlackBerry

Re: set font size, not in pixels

Hey, Thanks it Works..Thanks a lot..I solved my Problem..