3 Replies Latest reply on Nov 11, 2010 2:08 AM by 812727

    Setting LCD-AA text rendering hint has no effect on my JLabel


      I did ask for that question over at the old Sun Java forums, but I don't know if this has not been seen due to the change to the new Oracle forums, so I ask again here:

      I would like to use the rendering hint "VALUE_TEXT_ANTIALIAS_LCD_HRGB" to improve the look of the text rendering in Java under Windows XP. Using the JVM parameter
      I can set every text rendering to use LCD Anti Aliasing, on a per-JVM-basis.

      But I want the rendering hint "VALUE_TEXT_ANTIALIAS_LCD_HRGB" just for a special kind of JLabel component, so I tried to set this hint before the rendering of that component this way:
      public class MyAALcdLabel extends JLabel {
        protected void paintComponent(Graphics g) {
          Graphics2D g2d = (Graphics2D)g;
      But this just does not work (tested under Windows XP). With the JVM parameter above the label has the nice LCD Anti Aliasing, but with only the code above it does not use that AA.

      Does anyone know why setting that rendering hint before calling "super.paintComponent(g2d);" does not work?

      Thanks a lot for your help!
        • 1. Re: Setting LCD-AA text rendering hint has no effect on my JLabel

          First, I'm not an expert at all on font rendering.

          1) the jvm property setting -Dawt.useSystemAAFontSettings=lcd suggests only an indication that an lcd screen is used. It does not imply any of the rendering hint values explicitly.

          2) A search through the core java sources for various text antialiasing hints only produces some hits in FontRenderContext. For LCD_HRGB I cannot find any hit. That suggests that it is not queried at all. (at least not in the sources delivered with the JDK)

          3) A Google revealed more people having trouble with these text antialiasing hints. So apparently you are not the only one :-)

          • 2. Re: Setting LCD-AA text rendering hint has no effect on my JLabel
            Hello pietblok,

            thanks a lot for your reply and sorry for my late answer.

            I still do not understand why setting the hint on the Graphics object does not work for a JLabel. Now I just set the JVM parameter "awt.useSystemAAFontSettings=lcd" from within my code when the application starts via "System.setProperty", and it works for me under Windows XP.
            • 3. Re: Setting LCD-AA text rendering hint has no effect on my JLabel
              In Java 6, from my investigations, Swing components automatically detect the system settings and apply LCD antialiasing when drawing text. However:

              There is a bug in Java2D that defeats LCD antialiasing: if the Graphics2D ANTIALIASING hint is ON, then the TEXT_ANTIALIASING_LCD hint is ignored, and you get standard greyscale text antialiasing. It appears this may be fixed in Java 7. In the meantime, set ANTIALIASING to OFF in the graphics context.

              You shouldn't have to mess with the TEXT_ANTIALIASING hint, as it is set when the text is drawn, deep down in SwingUtilities2.drawString(). You would only need to manipulate this hint if you are drawing text yourself using Java2D primitives.

              Note that on Windows XP, the system setting that drives the automatic behavior is in Control Panel / Display / Appearance / Effects / 'Use the following method to smooth edges of screen fonts'. This must be set to ClearType to enable automatic LCD AA in Swing. The -Dawt.useSystemAAFontSettings=lcd setting overrides the detection of system settings. But due to the bug in Java2D, it means that you may sometimes see subpixel antialiasing and sometimes not, depending on the current state of the antialias hint in the graphics context.

              -- Samuel