Advertisement Jump to content


This topic is now archived and is closed to further replies.


can java applets display any font u want?

This topic is 5842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im workin on a java applet and im using a specific font that some other ppl might not have..if i include the font on the server will the java applet automatically "download" it i guess and display it? does it get embedded? basically i want the ppl to see the font im usin regardless of whether its in their local fonts folder or not..

Share this post

Link to post
Share on other sites
The Java Platform ships with a set of fonts belonging to different font families. This allows applets to have a consistent look across different platforms.

While you can expose fonts available on the client''s system, there is not guarantee that they would be available on all systems.

GraphicsEnvironment gEnv =
String envfonts[] = gEnv.getAvailableFontFamilyNames();

Fortunately, like most things java, there is an SDK supported way of doing things. Since it is illegal for an applet to download files onto the client''s machine, you simply create the font in memory.

To create you custom font, you can use:
java.awt.Font.createFont(int fontFormat, InputStream fontStream)

This method allows you to create a truetype font in memory, that can then be loaded into your graphic context for drawing text on the screen etc...

Depending on the format you have the desired font in (it will probably be a .ttf file in your system), it should be relatively simple to use this method. First pass in TRUETYPE_FONT for fontFormat, then you will want to create an input stream for the font data (if the truetype font tables are already in the required order in the font file, all you need to do is create a stream to that file).

After that, you may want to use the method deriveFont. This lets you create new font objects (of different sizes etc..) out of the one you just created (which defaults to 1point in size).

Try looking up those 2 functions in the online java documentation; there might even be examples online. good luck.

Share this post

Link to post
Share on other sites
Seeing how this is a game development site (and your applet might well be a game), I should mention another alternative commonly used in games: bitmap fonts.

Bitmap fonts mean that each character is represented by an image -- this way, fonts can be rendered quickly without the need of a TT font engine (seeing how you are using Java, raw speed may not be required anyway).

Bitmap fonts in java have the further advantage (or disadvantage depending on your perspective) of always being identical. Each system tends to render true type fonts differently; in fact, even the font''s point size is subject to platform specific interpretation.

Implementing a bitmap font is fairly simple, and many sources (including this site) contain resources on how to achieve that goal.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!