containerListener

Runs onChildrenChange whenever a child is added to or removed from the container. Requires a Container target.

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

Return

this chain with the container callback declared on it.

Parameters

onChildrenChange

receives the event, whose child is the component that joined or left; the composition's own inserts and removals report here too.

See also


fun SwingModifier.containerListener(onComponentAdded: (ContainerEvent) -> Unit = UNDECLARED, onComponentRemoved: (ContainerEvent) -> Unit = UNDECLARED): SwingModifier

Runs onComponentAdded when a child joins the container and onComponentRemoved when one leaves. Requires a Container target. A direction 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 container callbacks declared on it.

Parameters

onComponentAdded

runs once the child is in the container, so its index is already the new one.

onComponentRemoved

runs once the child is out, so its parent is already null.

See also


Attaches a ContainerListener (addContainerListener/removeContainerListener). Requires a Container target.

Return

this chain with the container 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