Skip to content

TabView

Since 2.2.1

TabView is a tabbed-panel container. It maintains a horizontal scrollable row of Tab headers and a content pane that shows the currently-selected tab's contents. Switching tabs shows the new content and hides all others.

Only Tab (and its subclasses) can be added as children in the editor.

INFO

Everything documented on UIElement (layout, styles, events, data bindings, etc.) applies here too.


Usage

java
var tabView = new TabView();

var content1 = new UIElement();
content1.addChild(new Label().setText("Settings content", false));

var content2 = new UIElement();
content2.addChild(new Label().setText("Info content", false));

tabView.addTab(new Tab().setText("Settings"), content1);
tabView.addTab(new Tab().setText("Info"), content2);

tabView.setOnTabSelected(tab -> System.out.println("Selected: " + tab));
parent.addChild(tabView);

XML

xml
<tab-view>
    <tab text="Settings">
        <tab-content>
            <label>Settings content here</label>
        </tab-content>
    </tab>
    <tab text="Info">
        <tab-content>
            <label>Info content here</label>
        </tab-content>
    </tab>
</tab-view>

Each &lt;tab&gt; element is a tab header; its &lt;tab-content&gt; child describes the content pane displayed when that tab is active.


Internal Structure

IndexFieldCSS classDescription
0tabContentContainer.__tab-view_tab_content_container__Pane that holds all content elements (only the active one is displayed).
1tabHeaderContainer.__tab-view_tab_header_container__Row of tab headers (contains the tabScroller).

The tabScroller is a ScrollerView nested inside tabHeaderContainer:

FieldCSS classDescription
tabScroller.__tab-view_tab_scroller__Horizontally-scrollable view holding all tab headers.

Fields

NameTypeAccessDescription
tabHeaderContainerUIElementpublic finalContainer for the tab header row.
tabScrollerScrollerViewpublic finalHorizontal scroller holding the tab headers.
tabContentContainerUIElementpublic finalContainer for all content panes.
tabContentsBiMap&lt;Tab, UIElement&gt;private (getter)Bidirectional map of tab headers ↔ content panes.
selectedTabTabprivate (getter/nullable)The currently-selected tab.

Methods

MethodReturnsDescription
addTab(Tab, UIElement)TabViewAppends a new tab and its content pane. Selects it if it is the first.
addTab(Tab, UIElement, int)TabViewInserts a tab at a specific index.
removeTab(Tab)TabViewRemoves a tab and its content. Selects the next tab if the removed one was selected.
selectTab(Tab)TabViewSelects a tab, showing its content and hiding all others.
clear()TabViewRemoves all tabs and content.
setOnTabSelected(Consumer&lt;Tab&gt;)Callback invoked when any tab is selected.
tabHeaderContainer(Consumer&lt;UIElement&gt;)TabViewConfigures the header container.
tabScroller(Consumer&lt;ScrollerView&gt;)TabViewConfigures the header scroller.
tabContentContainer(Consumer&lt;UIElement&gt;)TabViewConfigures the content container.

Released under the MIT License.