Improving the look of fonts under Swing

As I said in my last post, I've spent quite a bit of time over the last few days fiddling with Java, and one of the things that bugged me is that the fonts look pretty crappy because they aren't antialiased. The only way to do this in JVM 1.4 and before is to subclass every widget and/or install your own PLAF (Pluggable Look And Feel) - there are a couple of projects which have done this, for example wraplf and smoothmetal. However, as of JRE 1.5, there's a way to do this globally for your application:

    System.setProperty("swing.aatext", "true");

Unfortunately this doesn't work inside an applet as writing to a system property is forbidden and you'll get a security exception. You can achieve the same effect by adding -Dswing.aatext=true to the command line. If you want to set this for all applets you load, open up the Java Plugin Manager, go to the Java tab and click on the View button under Java Applet Runtime Settings. In the table, click on the Java Runtime Parameters field for the 1.5 JRE and enter -Dswing.aatext=true as the value, then save and exit. Voila, all your applets will use antialiased fonts.

Tags : ,
Categories : Java, Tech