CardPanel

@Composable
fun CardPanel(selectedCard: String, modifier: SwingModifier = SwingModifier, hgap: Int = 0, vgap: Int = 0, content: @Composable CardPanelScope.() -> Unit)

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

selectedCard

the key of the card to show

modifier

the SwingModifier applied to the panel

hgap

the horizontal gap between the panel's left/right edges and the shown card; 0 by default, so the card reaches those edges

vgap

the vertical gap between the panel's top/bottom edges and the shown card; 0 by default, so the card reaches those edges

content

the composable content of the deck; see CardPanelScope

See also