Skip to content

Tab

Since 2.2.1

Tab is a single tab header element. It displays a text label and changes its background texture depending on whether it is idle, hovered, or selected. Tabs are normally managed inside a TabView, which handles the selection logic.

INFO

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


Usage

Tabs are usually created alongside a TabView:

java
var tabView = new TabView();

var tab1 = new Tab().setText("Settings");
var tab2 = new Tab().setText("Info");

tabView.addTab(tab1, new UIElement()); // tab + its content pane
tabView.addTab(tab2, new UIElement());
parent.addChild(tabView);

XML

xml
<tab-view>
    <tab text="Settings">
        <tab-content>
            <!-- children of the Settings pane go here -->
        </tab-content>
    </tab>
    <tab text="Info">
        <tab-content>
            <!-- children of the Info pane go here -->
        </tab-content>
    </tab>
</tab-view>

INFO

Tab is normally placed as a direct XML child of &lt;tab-view&gt;. The &lt;tab-content&gt; element specifies the content pane associated with this tab.

XML AttributeTypeDescription
textstringLabel text (literal, not translated).

Internal Structure

IndexFieldCSS classDescription
0text.__tab_text__The Label element showing the tab text.

Tab Style

TabStyle mirrors Button's three-state texture system but uses the three states for idle, hovered, and selected.

INFO

base-background

Background when the tab is idle (not selected, not hovered).

Default: Sprites.TAB_DARK

java
tab.tabStyle(style -> style.baseTexture(myIdleTexture));

INFO

hover-background

Background when the mouse hovers over the tab.

Default: Sprites.TAB_WHITE

java
tab.tabStyle(style -> style.hoverTexture(myHoverTexture));

INFO

pressed-background

Background when the tab is selected (the pressed-background property is reused for the selected state).

Default: Sprites.TAB

java
tab.tabStyle(style -> style.selectedTexture(mySelectedTexture));

CSS State

When a tab is selected, it gains the CSS class .__tab_selected__. The associated content element gains .__tab_content_selected__.


Fields

NameTypeAccessDescription
textLabelpublic finalThe label element.
tabStyleTabStyleprivate (getter)Current tab style.

Methods

MethodReturnsDescription
setText(String)TabSets the label text (literal).
setText(String, boolean)TabSets label text. true = translatable.
setText(Component)TabSets label from a Component.
setDynamicText(Supplier&lt;Component&gt;)TabBinds label to a data supplier for live updates.
textStyle(Consumer&lt;TextElement.TextStyle&gt;)TabConfigures the label's text style fluently.
tabStyle(Consumer&lt;TabStyle&gt;)TabConfigures TabStyle fluently.
setOnTabSelected(Runnable)Callback invoked when this tab is selected.
setOnTabUnselected(Runnable)Callback invoked when this tab is deselected.
getContent()UIElement (nullable)Returns the content pane from the parent TabView.
getTabView()TabView (nullable)Returns the parent TabView.

Released under the MIT License.