mouseListener

Runs onMouseEvent for every mouse event on the component - a click, a press, a release, the pointer entering and the pointer leaving alike, so one interaction reports more than once. Declare the events one by one to tell them apart.

onMouseEvent is read when the event fires, so writing a fresh lambda on every recomposition registers nothing again.

Return

this chain with the mouse callback declared on it.

Parameters

onMouseEvent

receives the event, whose id tells the five apart; a disabled component reports them too, since it is Swing's own listeners that check isEnabled.

See also


fun SwingModifier.mouseListener(onMouseClicked: (MouseEvent) -> Unit = UNDECLARED, onMousePressed: (MouseEvent) -> Unit = UNDECLARED, onMouseReleased: (MouseEvent) -> Unit = UNDECLARED, onMouseEntered: (MouseEvent) -> Unit = UNDECLARED, onMouseExited: (MouseEvent) -> Unit = UNDECLARED): SwingModifier

Runs each lambda on the mouse event it is declared for. An event left undeclared reports nowhere.

Each lambda is read when its event fires, so writing a fresh one on every recomposition registers nothing again.

Declaring none at all is refused.

Return

this chain with the mouse callbacks declared on it.

Parameters

onMouseClicked

runs on a release over the component the press went to; a drag in between can suppress it. clickCount is 2 on the second event of a double click.

onMousePressed

runs when a button goes down; read isPopupTrigger here and on the release, since the platform decides which of the two carries it.

onMouseReleased

runs when the button comes back up, wherever the pointer is by then.

onMouseEntered

runs when the pointer moves onto the component.

onMouseExited

runs as soon as the pointer leaves, a drag that began here included; the drag itself keeps reporting through mouseMotionListener until the button comes up.

See also


Attaches a MouseListener (addMouseListener/removeMouseListener).

Return

this chain with the mouse listener declared on it.

Parameters

listener

attached by identity, so a remembered instance stays put while a fresh one on every pass is detached and re-added.

See also