views:

153

answers:

1

Is it possible to use a font not on the user's machine for text displayed in a java applet. Like linking to a ttf font file in the same location as the java applet almost in an @fontface fashion.

+2  A: 

You can use Font.createFont with fontFormat TRUETYPE_FONT:

Font f = Font.createFont( Font.TRUETYPE_FONT, new FileInputStream("font.ttf") );

As also described in Sun-Tutorial Working with Text APIs the returned font size is 1 pt, you can change this afterwards:

f = font.deriveFont(12f);
Peter Lang
Thank you, this works. But if I have it on a server I get FilePermissionException read error when it tries to access the font file.Serverside the code and font file have read and execute permissions. What do I have to do to grant my code access to the font file?
Jaxsun
@Jaxsun: Try to put the font file into your jar-file if possible, that should solve permission problems. If that's not an option, consider asking another question.
Peter Lang