BlackBerryForums.com : Your Number One BlackBerry Community      

»Sponsored Links



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

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.
   
Reply With Quote
Sponsored Links
Please Login or Register to Remove these Advertisements!

  (#2 (permalink)) Old
Ivanov Offline
Thumbs Must Hurt
 
Posts: 185
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Default 07-18-2008, 05:21 PM

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

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.
   
Reply With Quote
  (#4 (permalink)) Old
flameheels Offline
New Member
 
Posts: 9
Join Date: Jul 2008
Model: 8800
PIN: N/A
Carrier: MTS
Default 07-18-2008, 05:53 PM

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

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.
   
Reply With Quote
  (#6 (permalink)) Old
flameheels Offline
New Member
 
Posts: 9
Join Date: Jul 2008
Model: 8800
PIN: N/A
Carrier: MTS
Default 07-18-2008, 08:26 PM

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
   
Reply With Quote
  (#7 (permalink)) Old
richard.puckett Offline
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Posts: 212
Join Date: Oct 2007
Location: Seattle, WA
Model: 8800
PIN: N/A
Carrier: AT&T
Default 07-18-2008, 10:47 PM

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.
   
Reply With Quote
  (#8 (permalink)) Old
flameheels Offline
New Member
 
Posts: 9
Join Date: Jul 2008
Model: 8800
PIN: N/A
Carrier: MTS
Default 07-19-2008, 01:17 PM

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

Thanks
   
Reply With Quote
Reply


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-2008 BlackBerryNews.com, BlackBerryFAQ.com, BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of Research In Motion Limited.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.1