clip

fun SwingModifier.clip(shape: Shape, antialias: Boolean = false): SwingModifier

Clips everything inside it to shape's outline - the component's content, its border and, on a container, its children.

The cut is hard-edged by default: Graphics2D.clip produces no partially covered pixels, so a curve or a diagonal shows stair-stepping. antialias trades that for a soft edge, at the cost of painting the content into an offscreen raster and masking it, which a hard clip does not need. A rectangle has no edge to soften and is better left hard.

Inside its layout bounds, a clip changes how a component looks, not what it does: a circle-clipped container still takes a click in its corners. A child placed past the decorated box is cut away there, and a press there does not reach it.

Return

this chain with the clip declared on it.

Parameters

shape

the outline to cut to, resolved against the decorated box.

antialias

whether a pixel the outline covers in part is kept in part; false by default.

See also