TabbedPane

@Composable
fun TabbedPane(selectedIndex: Int, onSelectedIndexChange: (Int) -> Unit, modifier: SwingModifier = SwingModifier, tabPlacement: Int = JTabbedPane.TOP, tabLayoutPolicy: Int = JTabbedPane.WRAP_TAB_LAYOUT, content: @Composable TabbedPaneScope.() -> Unit)

A stack of pages of which one shows at a time, picked from a strip of tabs - a JTabbedPane. The pane holds which tab is selected and reports the tab the user clicks.

A pane holds each child as the page of a tab rather than as an indexed child of a layout, so every child of content declares the tab it is the body of on its own modifier, with SwingModifier.tab(...) - the one region a pane offers (see TabbedPaneScope). A child declaring no tab is refused as it arrives, naming the pane and that call. A pane shows one tab per child and any number of them, so two children declaring a tab are two tabs.

Tabs are dynamic: emitting or dropping a child adds or removes the tab it is the body of, and a tab's title/icon/tooltip/enabled update on recomposition. The selected tab is controlled via selectedIndex, and onSelectedIndexChange reports the tab the user selects; a click the caller does not answer with a matching selectedIndex is settled back, so the pane returns to the declared tab. A tab may also carry a header composable that renders the tab in the strip in place of its title and icon.

selectedIndex is -1 for no selected tab, the value a JTabbedPane itself holds while none is selected. Any other value has to name a tab that is there: where it names none - dropping the selected tab without moving the index leaves it naming none - the pane falls back on a neighbor and reports that tab through onSelectedIndexChange, since it is the tab the pane is on and not the one declared.

TabbedPane(selectedIndex = sel, onSelectedIndexChange = { sel = it }) {
Column(SwingModifier.tab("General")) { GeneralSettings() }
Column(SwingModifier.tab("Advanced", enabled = false)) { AdvancedSettings() }
Column(SwingModifier.tab("Console", header = { Label("Console") })) { Console() }
}

Parameters

selectedIndex

the index of the selected tab, or -1 for none (controlled); -1 while the pane holds tabs leaves the strip with no tab selected and no page shown

onSelectedIndexChange

callback invoked with the index of the tab the user selects, and with the tab the pane is left on where selectedIndex names no tab of the strip

modifier

the SwingModifier applied to the underlying JTabbedPane

tabPlacement

where the tab strip is drawn; TOP by default

tabLayoutPolicy

how the tab strip handles overflow; the default WRAP_TAB_LAYOUT wraps the tabs that do not fit onto further runs of the strip, and a look and feel supporting only one of the policies ignores it

content

the composable content of the pane, one child per tab; see TabbedPaneScope

See also


@Composable
fun TabbedPane(selectedIndex: Int, changeListener: ChangeListener, modifier: SwingModifier = SwingModifier, tabPlacement: Int = JTabbedPane.TOP, tabLayoutPolicy: Int = JTabbedPane.WRAP_TAB_LAYOUT, content: @Composable TabbedPaneScope.() -> Unit)

A TabbedPane driven by a raw ChangeListener instead of an onSelectedIndexChange lambda. The listener is notified of the tab the user selects, and of the tab the pane is left on where selectedIndex names no tab of the strip, reading the new selection off the event's source pane; the latest declared instance is the one notified, so the listener may be declared inline.

Parameters

selectedIndex

the index of the selected tab, or -1 for none (controlled); -1 while the pane holds tabs leaves the strip with no tab selected and no page shown

changeListener

the listener notified when the user selects another tab, and when the pane is left on a tab selectedIndex does not name

modifier

the SwingModifier applied to the underlying JTabbedPane

tabPlacement

where the tab strip is drawn; TOP by default

tabLayoutPolicy

how the tab strip handles overflow; the default WRAP_TAB_LAYOUT wraps the tabs that do not fit onto further runs of the strip, and a look and feel supporting only one of the policies ignores it

content

the composable content of the pane, one child per tab; see TabbedPaneScope

See also