views:

257

answers:

2

in the a swing app i'm rendering text with a custom JComponent, using Graphics.drawString(). here is a sample:
aa text
in that same app, i'm rendering text using a JTextPane. here is a sample:
alt text

can you notice how the lower sample is a little 'smudged'? well, i can't figure out how to make it look like the upper sample.

thanks, asaf :-)


update:

  • System.setProperty("awt.useSystemAAFontSettings","false") and "lcd" too aren't working.
  • ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF) in paint() isn't working
  • putClientProperty(sun.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, Boolean.TRUE) gives java.lang.ClassCastException: java.lang.Boolean cannot be cast to sun.swing.SwingUtilities2$AATextInfo
+1  A: 

If you want your result to look like the the upper sample, then you want to disable anti-aliasing.

The first sample in your question has anti-aliasing disabled and the second sample has it enabled.

According to http://mindprod.com/jgloss/antialiasing.html the following code should help:

jtextArea.putClientProperty(com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, Boolean.TRUE);

Notice that the reference to com.sun.java.* will make your application non-portable to non-Sun JVMs (and possibly to different versions of Sun JVMs).

Joachim Sauer
tried System.setProperty("awt.useSystemAAFontSettings","false") and "lcd" too, but w/o results.
Asaf
tried ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF) in paint(), but w/o results.
Asaf
and putClientProperty(sun.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, Boolean.TRUE) gives java.lang.ClassCastException: java.lang.Boolean cannot be cast to sun.swing.SwingUtilities2$AATextInfo
Asaf
thanks for pointing to the right direction
Asaf
A: 

putClientProperty(SwingUtilities2.AA_TEXT_PROPERTY_KEY, null);

Asaf
If this is the actual solution, please mark it as such (by toggling the "accepted answer" checkbox), TIA!
netzwerg
yeh, but SO makes me wait for 2 days...
Asaf