November 2004
Intermediate to advanced
1024 pages
27h 50m
English
By setting a clipping shape in the graphics context, you constrain all drawing operations to the interior of that clipping shape.
g2.setClip(clipShape); // but see below g2.draw(shape); // draws only the part that falls inside the clipping shape
However, in practice, you don't want to call the setClip operation, since it replaces any existing clipping shape that the graphics context may have. For example, as you will see later in this chapter, a graphics context for printing comes with a clip rectangle that ensures that you don't draw on the margins. Instead, call the clip method.
g2.clip(clipShape); // better
The clip method intersects the existing clipping shape with the new one that you supply.
If you just want to apply a clipping ...
Read now
Unlock full access