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
Trusted Contributor
maanbhati
Posts: 236
Registered: ‎07-28-2010
My Device: Not Specified

Problem in loading custom font from .ttf file in blackberry application

Hi All,

            I am developing an bb application in that i am loading .ttf file to implement  custom Font for my application, but the problem is first time when my application will start the custom Font is applying for my application but second and third time it is not applying custom Font.

 

my code is as following -

 

if

(FontManager.getInstance().load("Alcohole.ttf", "MyFont",

FontManager.

APPLICATION_FONT) == FontManager.SUCCESS) {

 

try{

FontFamily typeface = FontFamily.forName(

"MyFont");

Font myFont = typeface.getFont(Font.

PLAIN, 20);

FontManager.getInstance().setApplicationFont(myFont);

}

catch(ClassNotFoundException e) {

System.

out.println(e.getMessage());

}

}

 

 

 

Thanks To All. 

Please use plain text.
Developer
hemant_sain
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10

Re: Problem in loading custom font from .ttf file in blackberry application

Try this one may be it will help you.

 

public Font fontStyle(int style, int size)
	{
		FontFamily fontFamily;
		try
		{
			fontFamily=FontFamily.forName("Alcohole");
		}
		catch(ClassNotFoundException e1)
		{
			fontFamily=Font.getDefault().getFontFamily();
		}
		Font font=fontFamily.getFont(style, size);
		return font;
	}

 

Please use plain text.
Contributor
rafabas
Posts: 14
Registered: ‎09-20-2011
My Device: Developer

Re: Problem in loading custom font from .ttf file in blackberry application

Hi maanbhati,

 

Try to unload the font when closing your application.

 

FontManager.getInstance().unload("MyFont");

Please use plain text.