Graphics2D Rendering Context

The collection of state attributes associated with a Graphics2D object is referred to as the Graphics2D rendering context. To display text, shapes, or images, you set up the Graphics2D rendering context and then call one of the Graphics2D rendering methods, such as draw or fill. As the following figure shows, the Graphics2D rendering context contains several attributes.

To set an attribute in the Graphics2D rendering context, you use the set Attribute methods

The pen style : setStroke

that is applied to the outline of a shape. This stroke attribute enables you to draw lines with any point size and dashing pattern and to apply end-cap and join decorations to a line.

The fill style : setPaint

that is applied to a shape's interior. This paint attribute enables you to fill shapes with solid colors, gradients, and patterns.

The compositing style : setComposite

that is used when rendered objects overlap existing objects.

The transform : setTransform

that is applied during rendering to convert the rendered object from user space to device-space coordinates. Optional translation, rotation, scaling, or shearing transforms can also be applied through this attribute.

The clip : setClip

which restricts rendering to the area within the outline of the Shape used to define the clipping path. Any Shape can be used to define the clip.

The font : setFont

used to convert text strings to glyphs.

Rendering hints : setRenderingHints

that specify preferences in the trade-offs between speed and quality. For example, you can specify whether antialiasing should be used, if it's available.