JDK-8134320 : Add documentation for Swing anti-aliasing hints
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2015-08-24
  • Updated: 2020-01-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
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.

-----------------------------------  
Comments
This bug is "In Progress" status now, so re-targeting back to Fix Version 9. If you are not working on this bug fix anymore, please update the bug from "In Progress" to just "Open"
13-11-2015