Skip to main content

Using ttf font runtime in an applet

2 replies [Last post]
skinhat
Offline
Joined: 2009-02-26

I have a certain font I want to use with an applet that is not part of standard windows (is a ttf file)

Is it possible to use the font runtime in an applet without installing the font ttf file? Would be great if I could put the ttf file into a resource jar and use it within my swing components in my applet.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
anthony_p
Offline
Joined: 2006-07-24

The Java specification is your friend. Read:

http://download.oracle.com/javase/6/docs/api/java/awt/Font.html

and pay attention to the createFont() static methods.

skinhat
Offline
Joined: 2009-02-26

Thanks, createfont does the trick, though you need to use derivefont aswell which isn't clear in the specification but found the info in a demo.

Font font = Font.createFont(Font.TRUETYPE_FONT, Resource.getResourceAsStream("test.ttf"));
} catch(Exception e){
e.printStackTrace();
}

font = font.deriveFont(Font.PLAIN,16f);