10-06-2008 06:58 AM
Hello, what is the smallest achievable J2ME Font on the Blackberry Bold? I ask this, because
style = "plain" face = "proportional" size = "small"
seems to be already very big and very bold? Is there a way to get a smaller font, without leaving the J2ME "environment" ?
Solved! Go to Solution.
10-06-2008 11:33 AM
Please see the following link for an example on working with fonts.
http://na.blackberry.com/eng/developers/resources/
10-06-2008 01:13 PM
Hm, I could be wrong, but that seem to be rim api fonts, which I cannot use without rewriting my complete j2me graphics code to adapt it to rim? current code looks like this:
import javax.microedition.lcdui.Graphics;
[..]
graphics.setFont(...the j2me font here...);
[..]
graphics.drawString(label, x,y, Graphics.TOP | Graphics.LEFT);
10-07-2008 06:11 AM
Hm, as read on
I have to use either the standard ui or the rim ui - so I would have to rewrite big portions of the code?
Is there no way to keep the original j2me code and e.g. define how the smallest j2me font on the Blackberry looks like?
10-07-2008 03:14 PM
MIDlets do not have as much granular control over fonts as is available in a BlackBerry CLDC application. MIDlets are able to use 3 preset sizes (small, medium and large). In a BlackBerry CLDC application you can specify the font size you wish.
The 2 font classes can not be intermixed. MIDlets need to use javax.microedition.lcdui.Font and BlackBerry CLDC applications need to use net.rim.device.api.ui.Font.
10-08-2008 06:34 AM
Previously I did an midlet for the Blackberry 8800. There the font was already a little bigger as e.g. on the Nokia E90.
But the smallest plain j2me font on the Blackberry 9000 (Bold) looks not like small, it looks like at least medium or big and with bold style.
Is there no way one can influence how the smallest plain j2me font on the BB 9000 looks like?
10-08-2008 01:09 PM
10-16-2009 07:07 AM
I would first like to say Java and the GNU license agreement has given me a very big heart. This entire community has helped me tremendously to learn how to code, and giving back is the least I could do. I hope the community in turn helps me when I reach rough spots in the future. Remember I worked hard on this code and it took me hours of exhaustian and is finally working and i'm now giving it away for free, so please do the same for others. it's the idea not the code that makes the money.
That being said I present to you:
how to solve a midlet to blackberry font problem in 5 minutes of coding.
(please link to this thread as much as possible)
Step 1: Analyze what's going on between the 2 seperate API's and why it's so tough to change the fonts.
Step 2: Ask yourself how come the packages clash with each other?
Step 3: Ask yourself...can I change the font in general?
Step 4: Run the following preferably somewhere in the constructor..and somewhere far away from the paint method.
final FontFamily fontFamily[] = FontFamily.getFontFamilies(); font10 = fontFamily[0].getFont(FontFamily.CBTF_FONT, 16); Font.setDefaultFont(font10);
keep in mind you have to have the proper net_rim_api.jar installed(or in the proper folder and setup via the toolkit properly)..and in my case the following code is at the top of my class file and i'm using an external library on my toolkit.
import net.rim.device.api.ui.Font; import net.rim.device.api.ui.FontFamily;
now this is just a natural function used for both the blackberry UI apps, and midlets using the Blackberry net_rim_api.jar as an external package.
Those of you who are running a blackberrycanvas or any of the Touch events for the blackberry storm should automatically know what i'm talking about. Send me an Email if you're at all confused i'll get back to ya.
Anyways moving on...
Run this natural function and go ahead and test it using a common g.drawString("Hello World",20,20,g.TOP|g.LEFT);
Voila you should notice your font has changed to the font specified by Font.setDefaultFont(font10);
This is because the static method used changes all of the fonts..including the BlackBerryMenu font I might add.
Next do the following:
Step 5: Ask yourself....but what if I have seperate places that need seperate fonts?
Good question...I had that one for a while and found a brilliant answer.
Note the following:
Font BBFont = javax.microedition.lcdui.Font.getDefaultFont();
Here's what just happened, the code above grabs the existing default font set for the lcdui font. Or in our case the Midlet Font. As i've looked into it..no method exists to create a nice font that matches the blackberry one yet...but after calling
Font.setDefaultFont(font10);
in this case font is referenced as....
net.rim.device.api.ui.Font
it changes the font for both the system as well as the
javax.microedition.lcdui.Font
this is signifigant to us because now since we can store the changed setting we can make magic happen.
Step 6: Make the magic happen with the fonts.
Store any blackberry font you want using the following....
final FontFamily fontFamily[] = FontFamily.getFontFamilies(); Font font10 = fontFamily[4].getFont(FontFamily.CBTF_FONT, 16); Font.setDefaultFont(font10); javax.microedition.lcdui.Font bbfont = javax.microedition.lcdui.Font.getDefaultFont();
feel free to make the font a variable you can reference from the whole class..or store it in another class if you like.
then do this in the paint method...
protected void paint(Graphics g){
g.setFont(bbfont);
g.drawString("Hello World",20,20,g.TOP|g.LEFT);
}
you should notice the font has changed very nicely to your new font....voila make a function out of it, change the fonts up.
Step 7: bask in the glory of the magic.
So you're telling me if I call Font.setDefaultFont(myfont);
and I use a blackberry font...it'll change the current font..so I can then go grab that font and store it and then call it at a later time and it'll use that font?
Say I want Times New Roman!
Well if they have Times New Roman then be my guest....
but then later I want Ariel Black....
yep same process be my guest.....
But dude according to the forums I can't do this....
yeah well, and you can quote me on this one According to JavaLover53 you can use whatever font you want, so long as you make the font first..and it's highly recommended that you do it outside the paint function, and also recommended you store the fonts in an easy to access place in memory, I.E. at the very top
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import javax.microedition.lcdui.*;
public class BBFontCanvas extends Canvas {
javax.microedition.lcdui.Font timesnewroman;
javax.microedition.lcdui.Font bbalphasans;
public BBFontCanvas(){
final FontFamily fontFamily[] = FontFamily.getFontFamilies();
font10 = fontFamily[4].getFont(FontFamily.CBTF_FONT, 16);
Font.setDefaultFont(font10);
bbalphasans = javax.microedition.lcdui.Font.getDefaultFont();
//have fun and make another font...
font10 = fontFamily[0].getFont(FontFamily.CBTF_FONT, 20);
Font.setDefaultFont(font10);
timesnewroman = javax.microedition.lcdui.Font.getDefaultFont();
}
public void changeFont(int fontnum){
//i figure from here you can do a switch statement to change the font...
//or idk perhaps just do it by fontnum
//you guys gotta code that up haha.
//it'll probably look like this though...
//public void changeFont(int fontnum,javax.microedition.lcdui.Font thefont){}
//or maybe you wanta return a new font so....
//public javax.microedition.lcdui.Font getNewFont(int fontnum,javax.microedition.lcdui.Font thefont){}
//then make like a switch statement, and then call this to establish the fonts you want in advance and store //these fonts use them for classes you have for classes you've made like void setFont(Font myfont); <--- in
//that case your midlet class never even heard of the blackberry font so you're passing a normal lcdui font.
//anyways point being as long as g.setFont(myfont); has the proper font this stuff works. :-)
font10 = fontFamily[2].getFont(FontFamily.CBTF_FONT, 16);
Font.setDefaultFont(font10);
bbalphasans = javax.microedition.lcdui.Font.getDefaultFont();
}
public void paint(Graphics g){
g.setColor(0,0,0);
g.fillRect(500,500);
g.setColor(255,255,255);
//set the font to bbalphasans or in this case fontFamily[4] from the constructor...
g.setFont(bbalphasans);
g.drawString("Hello World",20,20,g.TOP|g.LEFT);
}
}
and for those of you who don't like comments....just look at this code instead...
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import javax.microedition.lcdui.*;
public class BBFontCanvas extends Canvas {
javax.microedition.lcdui.Font timesnewroman;
javax.microedition.lcdui.Font bbalphasans;
public BBFontCanvas(){
final FontFamily fontFamily[] = FontFamily.getFontFamilies();
font10 = fontFamily[4].getFont(FontFamily.CBTF_FONT, 16);
Font.setDefaultFont(font10);
bbalphasans = javax.microedition.lcdui.Font.getDefaultFont();
font10 = fontFamily[0].getFont(FontFamily.CBTF_FONT, 20);
Font.setDefaultFont(font10);
timesnewroman = javax.microedition.lcdui.Font.getDefaultFont();
}
public void changeFont(int fontnum){
font10 = fontFamily[2].getFont(FontFamily.CBTF_FONT, 16);
Font.setDefaultFont(font10);
bbalphasans = javax.microedition.lcdui.Font.getDefaultFont();
}
public void paint(Graphics g){
g.setColor(0,0,0);
g.fillRect(500,500);
g.setColor(255,255,255);
g.setFont(bbalphasans);
g.drawString("Hello World",20,20,g.TOP|g.LEFT);
}
}
anyways that's my font tutorial and I currently have amazing good working code. I'm so happy to finally utilize the blackberry fonts and this one just proves each and everything a UI app can do, minus of course the components made...a midlet can do as well on a blackberry.
They don't call it Java for nothing, if you know the ins and outs it's just like any cup of coffee it'll get you WIRED!
Enjoy and ask me questions if you can't get the fonts you want. This should solve all the problems for those of you who worked hard on your midlets and are having font issues...and for those of you who are lazy..simply change the default system font and everything will be of that font.
--JLover53
05-03-2010 04:07 AM
I'm receiving an 'cannot find symbol CBTF_FONT' error while trying to use your code. Any suggestions??? Thanks!
08-29-2011 06:32 PM
Thanks, your code works well. I am able to change my midlet font to a blackberry font. Thank you so much for sharing this!