aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Having trouble with java.awt.Font.getFont(String nm, Font font) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Having trouble with java.awt.Font.getFont(String nm, Font font)" Watch "Having trouble with java.awt.Font.getFont(String nm, Font font)" New topic
Author

Having trouble with java.awt.Font.getFont(String nm, Font font)

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
I am trying to load the Comic Sans font into my applet.

If I use this line:


it will work on machines where the font is available.

So for machines that don't have the Comic Sans font, I want to specify a default font, so I use:



...but then I get back the Sans Serif fault every time.

Does anyone know how to solve so that the desired font is loaded if available?

Thanks,
James
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
getFont(String nm, Font font) is looking for a system property for the value in the string. It then uses the value of that system property as the font name to load.

Try this instead


run the code with -DmyFont="Comic Sans MS-PLAIN-12" to set this system property to the correct value.
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Tim,

That didn't work, but I instead set the system property with:



...and that worked.

Thanks for the pointer!

Cheers,
James
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Having trouble with java.awt.Font.getFont(String nm, Font font)