10.8. Other Capabilities of Java 2D

Since Java 2D already does a lot of calculations compared to the old AWT, by default, many of the optional features to improve performance are turned off. However, for crisper drawings, especially for rotated text, the optional features should be turned on.

The two most important settings are to turn on antialiasing (smooth jagged lines by blending colors) and to request the highest-quality graphics rendering. This approach is illustrated below:

 RenderingHints renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); ... public void paintComponent(Graphics g) { super.paintComponent(g); ...

Get Core Web Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.