setContent
Sets the composable content of any JComponent (a JPanel, a window's content pane, ...).
With no parent the content joins the composition the container's own place in the Swing tree resolves to: an enclosing composition when the container is nested under one, otherwise the composition shared by the owning top-level Window, so every content composition in one window recomposes together. A window with no root pane - a bare java.awt.Frame - has nowhere to keep a shared composition, so content in one composes on a recomposer of its own. A container detached from any window is not an error: the content is mounted as soon as the container is attached to a window, and disposing the returned handle before that happens mounts nothing. A container in a window that has been disposed composes where it stands, on a composition that lasts as long as the handle returned here.
A parent drives the composition instead, and the content composes on this call, whatever the container is attached to - which is what reaches a container that is built to be read rather than shown. Everything mounted inside this content joins parent as well: a setContent naming no parent of its own on a container hanging under this one resolves to parent rather than to the composition its window shares. The caller owns what they pass: disposing the returned handle disposes this content composition and leaves parent running. A container that later ends up in a different window recomposes there only when that window's place resolves to a composition different from the one this content already composes under. Where the same composition still answers - a published host reached again through the container's new place, or parent itself where it is a recomposer of the caller's own, which no window ever shares - the content keeps its composition: only the window it reads and the recomposer it registers with catch up, and everything it remembered survives the move.
The content reads its LocalWindow from the composition it joins, and the window this container is in wherever that composition names none.
The content also reads a LifecycleOwner as its LocalLifecycleOwner, shared with everything this content hosts - a popup, a menu, an overlay. It is the owner the composition this content joins carries, so an owner provided over that composition - by a caller, or by a navigation library - reaches this content too. Failing that it is the owner of composed content this container hangs under, a window's own content as a rule. Content that finds neither is given an owner of its own following this container, and only such an owner is ended at DESTROYED by disposing the returned handle. A Window or Dialog composed in this content is a top-level window of its own and states an owner of its own, whatever stands over the declaration.
An owner reports RESUMED while the content it follows is in a window showing at full size that holds the keyboard focus, STARTED while that content is shown without the focus, and CREATED while it has no native peer - detached, or in a window Swing has not realized yet - or while its window is minimized. It answers for the content it was given to follow, so content reading an owner it did not get for itself reports where that window's content stands rather than where this container hangs. Since RESUMED is the focused state, repeatOnLifecycle(RESUMED) ends its work the moment the user switches to another window - work that should run for as long as the content is on screen belongs under STARTED.
Must be called on the Event Dispatch Thread.
Return
a DisposableHandle that disposes this content composition when invoked (or cancels it if it has not mounted yet). Must be disposed on the Event Dispatch Thread.
Parameters
the composition context this content joins and shares the recomposition scope of, and the one anything mounted inside this content joins. Defaults to null, meaning the composition the container's own place in the Swing tree resolves to.
the composable content to set
Sets the composable content of a Window (a javax.swing.JFrame, javax.swing.JDialog, or javax.swing.JWindow).
The content is hosted on the window's content pane and joins the composition shared across that window.
Must be called on the Event Dispatch Thread.
Return
a DisposableHandle that disposes the composition when invoked. Must be disposed on the Event Dispatch Thread.
Parameters
the composable content to set
Sets the composable content of a JMenuBar.
Joins a composition like JComponent.setContent: the enclosing composition when nested, otherwise what the owning window shares, on the terms stated there. A menu bar installed on a window shares that window's composition.
A menu bar is routinely built before it is installed on its frame (bar.setContent { ... } then frame.jMenuBar = bar), so at the call site it usually has no window ancestor yet. As with JComponent.setContent, that is not an error: the content is mounted the moment the menu bar gains a window ancestor (when it is installed on the frame) - and the menu tree reads that window as its LocalWindow, so an item's callback reaches the window its menu hangs off. Must be called on the Event Dispatch Thread.
Return
a DisposableHandle that disposes this menu-bar composition (or cancels it if it has not mounted yet). Must be disposed on the Event Dispatch Thread.
Parameters
the composable menu tree (Menu, MenuItem, ...)