views:

238

answers:

1

I have some Swing code (written in 1.6 for 1.6) that specifically sets the font in a text area to Courier, but on some Windows systems, this shows up as Arial (the system default?) instead. Does that mean a font is missing from the system? What is the behavior Java has when it can't find a font it is looking for? Does it complain? Does it log it somewhere? Does it immediately resort to using the system default? Is the behavior different between 1.4/1.5/1.6 versions of the JVM?

Has anyone else ever run into this? I was very surprised to have something different from what I HARDCODED into the application show up in the UI - and only on some systems. The core issue is that I need a monospaced font style for this particular case, and Arial is not monospaced. Is there some way to specify a fallback if a certain font is not found? Something like:

if font is available use "Courier" else use "monospaced"

???

+1  A: 

You should first check if "Courier" is among the results of GraphicsEnvironment.getAvailableFontFamilyNames()

I don't know any built-in mechanism in Java for "if-unavailable-fallback-to" behavior.

martin
I would be really surprised if Courier was missing on any windows system.
DrJokepu