SwingNodeUpdater

The receiver of the update block passed to SwingNode: the typed Swing component T is this inside set, update, init and reconcile.

Use set/update for reactive property updates, init for one-time setup after creation, and reconcile for unconditional reconciliation. Listeners are installed through the modifier mechanism - see org.jetbrains.compose.swing.modifier.listener.

Functions

Link copied to clipboard
fun applyMirror(mirror: MirrorState<*>)

Applies mirror to this node, so the mirror belongs to it - which is what lets MirrorState.report answer a change inside the event that made it rather than from an event of its own.

Link copied to clipboard
fun <C : Component, V> SwingNodeUpdater<C>.declare(value: V, mirror: MirrorState<V>, read: C.() -> V, write: C.(V) -> Unit, onSettled: C.(V) -> Unit = {})

Declares value onto a widget property the user can also change, keeping mirror in sync with it.

fun <C : Component, V> SwingNodeUpdater<C>.declare(value: V, mirror: MirrorState<V>, read: C.() -> V, write: C.(held: V, declared: V) -> Unit, onSettled: C.(V) -> Unit = {})

Declares value onto a widget property whose write is a transition rather than an assignment: write is handed what the widget holds alongside what is declared, so it can write only the part that differs and leave what the rest of the value anchors standing - the caret inside a document, above all. The held value is the one the settlement has already read, so the write costs no second read.

Link copied to clipboard
fun hostSubcompositions(context: CompositionContext?)

Publishes context on the component, so that a setContent call on a component below it joins this composition - sharing its scope and its CompositionLocals. Without it such a call joins whatever its place in the Swing tree resolves to - the content composition above it, or the one its window shares - so it recomposes with everything else there but sees none of the CompositionLocals this node stands under. A null context leaves the component hosting nothing.

Link copied to clipboard
inline fun init(crossinline block: T.() -> Unit)

Runs block, with the typed component as this, exactly once: on the pass that creates the node, after the set/update blocks declared above it in the same update lambda have run against the freshly built component. Use it for setup that must happen once at creation but needs a value set/update computed - a value the factory cannot see - and that reconcile would otherwise redo on every composition.

Link copied to clipboard
inline fun reconcile(crossinline block: T.() -> Unit)

Unconditionally schedules block to run against the typed component on every composition. Prefer set/update when a single changing value drives the update; reach for reconcile only when those are insufficient.

Link copied to clipboard
inline fun <V> set(value: V, crossinline block: T.(V) -> Unit)

Reactively applies value to the component. block runs, with the typed component as this and value as its argument, on the first composition and again only when value changes between recompositions.

Link copied to clipboard
inline fun <V> update(value: V, crossinline block: T.(V) -> Unit)

Reactively applies value to the component, but - unlike set - skips the very first composition. Use it when the factory already initialized the component with value (e.g. a constructor argument).