tags:

views:

267

answers:

1

I'm writing a Graphically intense application that renders a JLabel offscreen.

When I call the following line, ellipsis appear on the mac but not on the windows box.

g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
    RenderingHints.VALUE_FRACTIONALMETRICS_ON);

Now, I'm guessing that it's caused by Mac already doing some subpixel rendering of fonts, but I'd just like to confirm it.

Also, since on it's imperative that FRACTIONALMETRICS be enabled on windows (the app looks terrible otherwise), can anyone suggest a work around short of adding a check for not mac?

Thanks.

+1  A: 

The RenderingHints for FractionalMetrics are concerned with rounding floats to ints when sizing or kerning fonts. The glyphs themselves are unaffected by this setting. You can read all about this at the Java 2D FAQ.

You are correct that Java on Mac OS X is enabling text anti-aliasing at a system level, and Windows is not, but there's no need for a Mac-only check. What you should do is set the TextAntiAlias RenderingHint on instead.

gfx.setRenderingHint( 
        RenderingHints.KEY_TEXT_ANTIALIASING, 
        RenderingHints.VALUE_TEXT_ANTIALIAS_ON 
    );

Java 6 supports ClearType font rendering which is much better on LCD screens than the anti-aliasing that was in Java 5. ClearType often needs to be switched on Windows XP; it's somewhere in the display settings in the Control Panel. Then you need to run your Java program with the correct command-line arguments to enable it (or insert them into System.setProperty() before you display any Swing components):

java -Dawt.useSystemAAFontSettings=lcd [...your gubbins here...]
banjollity
thanks, the ClearType trick is nice to know but sadly beyond the version I'm targeting. Any idea what's causing the ellipsis in one but not the other then? Or is the anti-aliasing bumping the size up?
Allain Lalonde
Is the string being rendered the same, and is it in the same font? I can't remember if Mac Java apps use Lucida Grande by default or not. Sometimes a wide glyph like a capital W will invoke an ellipsis on a JLabel. If your layout manager allows, try making it a bit wider.
banjollity