Clipping

Every Graphics has an associated clipping rectangle. Clipping rectangles are so named because they clip rendering to the rectangle they represent. In addition, with the advent of the Java 2D Api, clipping can be set to an arbitrary shape instead of being restricted to a rectangle.

The methods below, which are repeated from “Graphics Parameters”, are provided by java.awt.Graphics for setting and getting the clipping region:

  • void setClip(int x, int y, int w, int h)

  • void setClip(Shape)

  • Rectangle getClipBounds()

  • Shape getClip()

  • void clipRect(int x, int y, int w, int h)

The first two methods set the clipping region. The first method sets the clipping region to a rectangle, and while the second sets it to an arbitrary shape.

The next two methods ...

Get Graphic Java™ 1.2, Volume I: AWT, Third 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.