An interesting bug in Java2D text rendering

July 2nd, 2007

I’ve started playing with custom alpha channel settings for certain component states. Look at the following screenshot:

Text rendering bug on JDK 6.0 2

The checkbox and the radio button on the second line are disabled. The checkbox and the radio button on the last line are selected and disabled. As you can see, in general, you would use three color schemes for three major component states: active (selected, rolled over, pressed), default and disabled. In most cases, the disabled color scheme uses the same color values as the default color schemes, but the overall colors are a little brighter. So, i was toying with the idea of using the same color scheme for both default and disabled states, but set arbitrary alpha for the disabled state.

The implementation is a little complicated (especially since there are so many core components), and this is what has been taking my time lately (with no posts on Substance in the past few days). And just when i thought it was progressing smoothly, i hit this:

Text rendering bug on JDK 6.0

It took almost two hours to isolate this problem to a small and complete test application which i posted at the Java2D forum over at So, don’t be surprised to see a few garbled strings if you’re running under the latest 4.0dev drops of Substance and using the experimental Autumn and Magma skins. I think that i’ll be able to find a workaround for this bug(?), but i’ll wait to see the replies on the forum linked above.

Update: Phil Race from Sun’s Java2D team has confirmed this bug and provided a workaround. See the thread at Java2D forum for the suggested workaround (confirmed to work on Vista). Thanks, Phil.