hostSubcompositions

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.

Read the context where the node is declared and hand it over here:

val context = rememberCompositionContext()
SwingNode(
factory = { JPanel() },
update = { hostSubcompositions(context) },
)

It is declared rather than taken by SwingNode itself because reading the enclosing context is work on every pass rather than a value a node remembers, and a node that hosts nothing would otherwise pay for it.

The component must be a javax.swing.JComponent, which is what carries the client property a descendant setContent walks up to find; anything else throws IllegalStateException.

Parameters

context

the composition a setContent below this component joins. Applied through set, so it takes a slot in the update block whether or not it is null.