LCD Subpixel Rendering
By Tor Norbye on May 20, 2010
While I'm on the topic of pixels -- here's another tip. This one is both Mac OSX and NetBeans (well, Swing) specific.
Subpixel rendering, an antialiasing technique, makes text look much sharper (wikipedia article).
Subpixel rendering was added to Java 6, so the NetBeans source editor looks great on Windows and Linux provided you are running Java 6. Antialiasing was never an issue on Macs, where the JDK used its own native graphics renderer which had subpixel rendering all along - until now!!
Here's NetBeans on Linux and Windows:
Let's zoom in. Notice the "strange" colors at the perimiter of the font strokes; they look strange here but oh-so-good at the proper resolution on an LCD:
Unfortunately, when Apple released Java 6 on the Mac, they switched the default graphics renderer over from their own "Quartz" renderer to the standard JDK one. That shouldn't be a problem, since Java already renders LCD text, right? Wrong! For reasons I don't know, subpixel rendering is NOT working on the Mac with the standard renderer. Therefore, by default, NetBeans text looks blurry (because it is only grayscale antialiased) on Macs.
This is easy to "fix". Just switch the rendering back to Quartz. You can do that with the following flag, added to the
netbeans.conf config file:
-Jflag just tells the NetBeans launcher that the rest of the flag is a flag for the Java interpreter, and the
-Dflag says set the system property
apple.awt.graphics.UseQuartzto true. Therefore, in your own Swing applications you can do the same thing, just drop the
(The config file is in a place like
/Applications/NetBeans/NetBeans 6.9 Beta.app/Contents/Resources/NetBeans/etc/netbeans.confand you would add these flags to the
Here is a before-versus-after screenshot; this will only make visual sense to you if you're viewing this on an LCD screen!
The subpixel rendering text is on the left.
Here's a zoomed in view, which shows the default (non-LCD renderered text):
And here's what you get when you turn on Quartz:
I presume Apple turned off Quartz by default in Java 6 for a reason. Does anyone know what it is? The JavaFX Release Notes mention some memory leaks. I've been using the flag to turn LCD text back on since I switched to Java 6 on the Mac a year ago, and it doesn't seem to have any adverse effects for normal NetBeans usage (mostly text oriented; I don't do UML editing etc).
More importantly, does anybody know why subpixel rendering from the JDK doesn't work on the Mac since it works everywhere else? Is there a way to trick it to work with rendering hints etc?
P.S. Speaking of launcher arguments - I have one other customization too. I add
-J-d32. This tells the JDK that I want a 32-bit VM. I haven't measured personally what this buys me, but I saw that Charlie Nutter recommended it for NetBeans usage, and he certainly knows his way about VM tuning parameters!