
Render ing Hints
Another graphics attribute used by the Graphics2D class is java.awt.Rendering-
Hints. This class is a mapping (a java.util.Map) from a set of rendering hint
names to a set of rendering hint values. Unlike with other attributes,
Graphics2D
defines more than one method to set the rendering hints attribute. setRendering-
Hints() specifies a new set of hints that replaces the old set of hints, while
addRenderingHints() adds a set of hints to the existing set and setRendering-
Hint() sets the value for a single hint in the current set of hints.
Rendering hints are suggestions to Java 2D about how it should perfor m its ren-
dering. The
RenderingHints class defines a number of constants whose names
begin with
KEY_. These constants repr esent the kind of hints you can give. The
class also defines a number of constants whose names begin with
VALUE_. These
ar e the legal values for the various hints. The names of the
VALUE constants make
it clear with which hint
KEY constant each value is associated.
The purpose of the hints is to allow you to request that Java 2D turn a particular
featur e, such as antialiasing, on or off. In addition, the hints allow you to suggest
what kind of speed versus quality trade-offs Java 2D should make. Remember that
these are hints and suggestions to Java 2D, not commands. Not all Java 2D imple-
mentations support all the hints, and differ ent implementations have differ ...