CardPanel
A JPanel under a CardLayout: a deck of cards of which exactly one is shown. The deck asks for room enough for its largest card, so showing another card does not resize it.
Each child names the card it is placed on through CardPanelScope, and selectedCard picks the card the deck shows:
CardPanel(selectedCard = page) {
Label(text = "Welcome", modifier = SwingModifier.card("welcome"))
Label(text = "Details", modifier = SwingModifier.card("details"))
}A card holds a single child; two children naming the same card are reported as an error on the event dispatch thread once the change pass that caused it has settled, so a pass that replaces a card's occupant need not take the outgoing child out before the incoming one arrives. The report reaches whatever handles an uncaught exception on that thread - by default the JDK's, which prints it and moves on, so an application that installs none of its own keeps running with both children on the card.
Dropping a child (e.g. behind an if) takes its card with it, and a selectedCard matching no card leaves the card currently on top showing. A child that names no card is placed on the deck's empty-named card, which an empty selectedCard shows; that card holds a single child like any other, so two children naming none are refused the way a card named twice is.
Parameters
the key of the card to show
the SwingModifier applied to the panel
the horizontal gap between the panel's left/right edges and the shown card; 0 by default, so the card reaches those edges
the vertical gap between the panel's top/bottom edges and the shown card; 0 by default, so the card reaches those edges
the composable content of the deck; see CardPanelScope