onPointerEvent

fun SwingModifier.onPointerEvent(onPress: (MouseEvent) -> Unit? = null, onRelease: (MouseEvent) -> Unit? = null, onClick: (MouseEvent) -> Unit? = null): SwingModifier

Installs mouse press/release/click handlers. onPress fires on MOUSE_PRESSED, onRelease on MOUSE_RELEASED, and onClick on a completed click; each receives the MouseEvent (button, click count, point, modifiers). This is the low-level complement to a widget's domain onClick: use it for arbitrary components (a Label, a FlowPanel) or for right/middle-button handling.

Multiple onPointerEvent applications all fire. Callbacks are read live, so passing fresh lambdas each recomposition is fine.

A callback left undeclared reports nowhere, and declaring none is refused.

Return

this chain with the pointer handlers declared on it.

Parameters

onPress

the platform decides whether a popup gesture is reported on the press or on the release, so check isPopupTrigger in both.

onRelease

still runs when the pointer has been dragged off the component, since the press holds the grab.

onClick

skipped when the pointer is dragged between press and release - on Windows and macOS for any movement at all, on Linux only once the drag leaves a few pixels around the press point.

See also