Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

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



...and that worked.

Thanks for the pointer!

Cheers,
James
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic