ExistingSwingNode

@Composable
inline fun <P : Component, R : Component, T : R> ExistingSwingNode(noinline claim: @DisallowComposableCalls P.() -> R?, modifier: SwingModifier = SwingModifier, crossinline update: @DisallowComposableCalls SwingNodeUpdater<T>.() -> Unit = {}, declaringCall: String? = null)

Configures a component its parent already built and keeps, such as a JScrollPane's scroll bars or a JLayer's glass pane, the way SwingNode configures a component its own factory builds.

The parent is the component of the node this one is composed directly under. claim runs on the parent when the node is created, and returns the component this node configures; it need not be a direct Swing child of the parent. P is the type of the parent, R the type claim returns, and T the type the node configures, which is R unless written narrower. A function reference infers the type parameters - ExistingSwingNode(claim = JScrollPane::getVerticalScrollBar) - and a lambda needs them written, with _ for R: ExistingSwingNode<JScrollPane, _, JScrollBar>(claim = { verticalScrollBar }). A getter typed wider than the part, such as JInternalFrame.getGlassPane, names the part's type as T: ExistingSwingNode<JInternalFrame, Component, Container>(claim = JInternalFrame::getGlassPane) { ... }.

claim is read once, when the node is created, as SwingNode reads its factory: a later claim is not called and changes nothing. The claim holds for the node's life. Relocated under another parent, such as by movableContentOf, the node is refused. A part the parent replaces afterwards keeps nothing of this node's declarations, so the code that replaces a part keys the node claiming it on that part - key(part) { ExistingSwingNode(...) } - and a new node claims the new part. Replacing a claimed part from outside that code is undefined behavior.

The node never adds, removes or moves the claimed component. When the node leaves the composition, every property modifier declared is given back and every listener it installed is removed; the component stays where its parent holds it. What update wrote stays on the component.

Within one composition, a component is claimed by at most one node at a time. A second node claiming it is refused, including a node that replaces the first one under a changed key. The refusal names the declaration by the region its slot names or, under a host that uses indexed children, by declaringCall. It names the claimed component's type when neither is given, or when the two declarations name different regions or calls. Separate content compositions do not see each other's claims, so a component claimed in two compositions is not detected.

Under a host that places children in regions, the node names the region its component is in with org.jetbrains.compose.swing.modifier.layout.slot without an attachment. Under an indexed host it names nothing. That is the one placement the node declares: the parent placed the component, so parent data such as layoutConstraint or a row's weight is refused.

Parameters

claim

finds the component this node configures on its parent. It is refused when the parent is not a P, or when it returns null or something that is not a T, naming the parent, the expected types and what was found.

modifier

the SwingModifier applied to the claimed component, after update has run.

update

typed update block; see SwingNodeUpdater.

declaringCall

the call that declares this node, written as a caller writes it, such as "GlassPane { }". A refusal of a second claim of the component names it. Under a host that places children in regions, the region the node's slot names is that name, so a declaring call is refused when the node is inserted, or, when set later, when a second claim of the component is inserted.


@Composable
inline fun <P : Component, R : Component, T : R> ExistingSwingNode(noinline claim: @DisallowComposableCalls P.() -> R?, modifier: SwingModifier = SwingModifier, crossinline update: @DisallowComposableCalls SwingNodeUpdater<T>.() -> Unit = {}, declaringCall: String? = null, childPlacement: ChildPlacement = ChildPlacement.Indexed, crossinline content: @Composable () -> Unit)

Container variant of ExistingSwingNode that composes content into the claimed container.

The claimed container keeps its own layout manager. P, R and T are those of the leaf overload.

When the node leaves the composition, the children content composed are removed from the container, and what update wrote - the layout included - stays on it.

Parameters

claim

finds the container this node configures on its parent; see the leaf overload.

modifier

the SwingModifier applied to the claimed container, after update has run.

update

typed update block; see SwingNodeUpdater.

declaringCall

the call that declares this node; see the leaf overload.

childPlacement

how children composed under this node are held; see ChildPlacement. Defaults to ChildPlacement.Indexed.

content

the composables the claimed container holds as its children.