setLifecycleOwner

fun JComponent.setLifecycleOwner(owner: LifecycleOwner?)

Sets owner as the LifecycleOwner that composition roots mounted at or under this component read, in place of one following the component itself, and clears it again when passed null.

A root resolves an owner in this order: the one the composition it joins carries, then the one this sets, and only where neither answers does it mint an owner following its own container. So a host setting one here decides the lifecycle of every root under it that inherits nothing - which is what a test harness needs, and what a host driving its content's lifecycle itself needs.

The owner set here is the caller's: nothing clears it when the content under it leaves, and a root that resolves it neither drives it nor ends it. Clear it from the same teardown that ends it.

Marked InternalSwingUiApi; it may change or be removed without notice in any release.

Parameters

owner

the LifecycleOwner to set, or null to clear the one set here.