BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-18-2008, 11:14 AM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Model: 8800
PIN: N/A
Carrier: MTS
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Font Size in RichEditField

Please Login to Remove!

Very simple question.

I need to be able to set the font size of a RichTextField. I have looked at other examples in the forums and cannot get it to work. What is the simplest way to change the font. Please show entire process as I am a noob.
Offline  
Old 07-18-2008, 05:21 PM   #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

never worked with RichTextField, but from other Fields... setFont() should do it
Offline  
Old 07-18-2008, 05:52 PM   #3 (permalink)
New Member
 
Join Date: Jul 2008
Model: 8800
PIN: N/A
Carrier: MTS
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you.
I am still trying to figure out how to use SetFont. It takes a Font object as a parameter, but from my understanding you can use FontFamly.GetFontFamilies to retrieve a suitable font.

I know how to do this with an array type such as:

FontFamily fontfam[] = FontFamily.getFontFamilies();
Font fon[] = new Font[2];
Font afont = Font;
fon[0] = fontfam[0].getFont(FontFamily.SCALABLE_FONT|Font.ITALIC, 18);
fon[1] = fontfam[1].getFont(FontFamily.SCALABLE_FONT, 24);

This also works for adding Italics.
I guess Im wondering if there is an easier way.
Offline  
Old 07-18-2008, 05:53 PM   #4 (permalink)
New Member
 
Join Date: Jul 2008
Model: 8800
PIN: N/A
Carrier: MTS
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry, there is an error above, the line
Font afont = Font;
should not be there
Offline  
Old 07-18-2008, 06:05 PM   #5 (permalink)
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is easier:

Font font = Font.getDefault().derive(Font.PLAIN, 14, Ui.UNITS_px);

That'll give you something close to a 14px font. You can request a font with a certain point size by specifying Ui.UNITS_pt.
__________________
Do your homework and know how to ask a good question.
Offline  
Old 07-18-2008, 08:26 PM   #6 (permalink)
New Member
 
Join Date: Jul 2008
Model: 8800
PIN: N/A
Carrier: MTS
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. That worked well. I actually used
Font font = Font.getDefault().derive(Font.ITALIC| Font.BOLD, 40, Ui.UNITS_px);

any ideas on how to give a font color, I tried

RichTextField colorField = new RichTextField("Hello") {
// Override the paint method to set Color.
public void paint(Graphics graphics) {

//graphics.setFont(fon[0]);
graphics.setColor(Color.RED);
super.paint(graphics);
}
};
add(colorField);

4.5 does not seem to recognize the paint(graphics) method
Offline  
Old 07-18-2008, 10:47 PM   #7 (permalink)
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

That works for me on 4.5.0. One thing to check (esp if you're using the JDE and it's not doing any of this for you, like a good IDE should) is that you're using

net.rim.device.api.ui.Graphics

and not

javax.microedition.lcdui.Graphics

It needs to be the first one to match the method signature from the Field class. I've seen people make this mistake before...
__________________
Do your homework and know how to ask a good question.
Offline  
Old 07-19-2008, 01:17 PM   #8 (permalink)
New Member
 
Join Date: Jul 2008
Model: 8800
PIN: N/A
Carrier: MTS
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow. You are right on the money!
That was exactly the problem, the wrong library file!

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.