18 December 2010

Java Swing anti-aliased font rendering

[Update 2011-04-03:  The Arch Wiki describes lots of options for the export below. I've been having good results with export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=setting']

Today I noticed fonts in my Swing-based Java apps were utterly hideous. They were no longer being rendered with anti-aliasing. I don't know if this is because today I logged into a minimal Openbox+fbpabel setup and GNOME was handling this automatically or if it's caused by some other subtle thingy.

No matter, it's pretty easy to fix. Add

export _JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on"

to your ~/.profile file. You'll probably then have to logout and back in. After this anti-alised rendering will be the default.

Supposedly, you can do this system-wide by adding

_JAVA_OPTIONS="-Dawt.useSystemAAFontSettings=on"

to your /etc/environment file, but I have not tried this.

Update There is one downside to this: the JVM will write Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on to the console. It's not a deal-breaker, but it is a little annoying.

No comments: