Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8134320

Add documentation for Swing anti-aliasing hints

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8, 9
    • client-libs
    • None

      There is a suggestion to add a documentation for anti-aliasing hints usage in Swing.
      See JDK-6302464

      --------------------------------------

      The Swing UIDefaults manager recognises two {@code RenderhintHint}s related
      to text rendering : RenderingHints.KEY_TEXT_ANTIALIASING and RenderingHints.LCD_CONTRAST.

      These values are meant to be obtained from the desktop property "awt.font.desktophints"
      <ADD LINK HERE>
      http://docs.oracle.com/javase/7/docs/api/java/awt/doc-files/DesktopProperties.html

      < ADD SAMPLE CODE HERE>
              Map map = (Map) (Toolkit.getDefaultToolkit()
                      .getDesktopProperty("awt.font.desktophints"));

              if (map != null) {
                  UIManager.getDefaults().put(RenderingHints.KEY_TEXT_ANTIALIASING,
                          map.get(RenderingHints.KEY_TEXT_ANTIALIASING));
                  UIManager.getDefaults().put(RenderingHints.KEY_TEXT_ANTIALIASING,
                          map.get(RenderingHints.KEY_TEXT_LCD_CONTRAST));
              }

      These are used internally to help certain of Swing's standard L&Fs match the
      native desktop rendering. This is configured only on concrete L&F classes.
      If an application uses a custom LookAndFeel that sub-classes the BasicLookAndFeel
      and always delegate text rendering to the super-class and wants the same behaviour
      it should install these hints in the UIDefaults of its concrete class get this behaviour.
      Ideally the custom L&F will do so itself, but unless or until it does, then the application
      can install the hints directly.

      These can be enabled or over-ridden on a per-component instance by using
      JComponent.putClientProperty(..) instead.

      <ADD SAMPLE CODE HERE>
                  component.putClientProperty(RenderingHints.KEY_TEXT_ANTIALIASING,
                          RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
                  component.putClientProperty(RenderingHints.KEY_TEXT_LCD_CONTRAST, 200);


      For a custom L&F or a custom component that does not delegate to the BasicLookAndFeel,
      i.e. one that directly draws text itself using Java 2D APIs, then it must read and use
      the desktop properties itself.

          public class CustomLookAndFeel extends BasicLookAndFeel {

              @Override
              protected void initClassDefaults(UIDefaults table) {
                  super.initClassDefaults(table);
                  Map map = (Map) (Toolkit.getDefaultToolkit()
                          .getDesktopProperty("awt.font.desktophints"));

                  if (map != null) {
                      table.put(KEY_TEXT_ANTIALIASING, map.get(RenderingHints.KEY_TEXT_ANTIALIASING));
                      table.put(KEY_TEXT_LCD_CONTRAST, map.get(RenderingHints.KEY_TEXT_LCD_CONTRAST));
                  }
              }
          }



      Note: The Motif L&F ignores these hints because it is emulating the aliased rendering of X11.
      ImplNote: Remote X11 rendering of anti-aliased text may cause perceptible lag.
      The implementation of the standard L&Fs may disable text anti-aliasing in this case.

      -----------------------------------

            prr Philip Race
            alexsch Alexandr Scherbatiy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: