Class TabbedLayout


public class TabbedLayout extends StyledElement<TabbedLayout>
A layout with a tab bar and swappable content panels.

TabbedLayout provides a tabbed interface where clicking a tab header switches the visible content panel. Only one tab can be active at a time.

Features:

  • Horizontal or vertical tab orientation
  • Customizable tab and content styling
  • Programmatic tab selection

Usage:


 // Create tabbed layout
 TabbedLayout tabs = new TabbedLayout();
 tabs.addTab("General", generalSettings);
 tabs.addTab("Security", securitySettings);
 tabs.addTab("Advanced", advancedSettings);

 // Select second tab
 tabs.selectTab(1);

 // Vertical tabs
 TabbedLayout sidebar = TabbedLayout.vertical();
 sidebar.addTab("Dashboard", dashboardContent);
 sidebar.addTab("Reports", reportsContent);
 
Since:
2025
Version:
1.0
Author:
Marvin P. Warble Jr.
See Also:
  • Constructor Details

    • TabbedLayout

      public TabbedLayout()
      Constructs a TabbedLayout with horizontal tabs.
    • TabbedLayout

      public TabbedLayout(TabbedLayout.Orientation orientation)
      Constructs a TabbedLayout with the specified orientation.
      Parameters:
      orientation - the tab orientation
  • Method Details

    • initialize

      protected void initialize()
      Builds the element tree for the tabbed layout.
      Overrides:
      initialize in class StyledElement<TabbedLayout>
    • horizontal

      public static TabbedLayout horizontal()
      Creates a TabbedLayout with horizontal tabs.
      Returns:
      a new horizontal TabbedLayout
    • vertical

      public static TabbedLayout vertical()
      Creates a TabbedLayout with vertical tabs.
      Returns:
      a new vertical TabbedLayout
    • addTab

      public TabbedLayout addTab(Tab tab)
      Adds a Tab to the layout.
      Parameters:
      tab - the tab to add
      Returns:
      this TabbedLayout for method chaining
    • addTab

      public Tab addTab(String label, Element<?> content)
      Creates and adds a Tab with the specified label and content.
      Parameters:
      label - the tab label
      content - the tab content
      Returns:
      the created Tab for further customization
    • selectTab

      public TabbedLayout selectTab(int index)
      Selects the tab at the specified index.
      Parameters:
      index - the tab index
      Returns:
      this TabbedLayout for method chaining
    • selectTab

      public TabbedLayout selectTab(Tab tab)
      Selects the specified tab.
      Parameters:
      tab - the tab to select
      Returns:
      this TabbedLayout for method chaining
    • getActiveIndex

      public int getActiveIndex()
      Returns the currently active tab index.
      Returns:
      the active tab index, or -1 if no tab is active
    • getActiveTab

      public Tab getActiveTab()
      Returns the currently active tab.
      Returns:
      the active Tab, or null if no tab is active
    • getTab

      public Tab getTab(int index)
      Returns the tab at the specified index.
      Parameters:
      index - the tab index
      Returns:
      the Tab, or null if index is out of bounds
    • getTabs

      public List<Tab> getTabs()
      Returns all tabs.
      Returns:
      a list of all Tabs
    • getTabCount

      public int getTabCount()
      Returns the number of tabs.
      Returns:
      the tab count
    • setTabGap

      public TabbedLayout setTabGap(int gap)
      Sets the gap between tabs.
      Parameters:
      gap - the gap in pixels
      Returns:
      this TabbedLayout for method chaining
    • setTabGap

      public TabbedLayout setTabGap(String gap)
      Sets the gap between tabs.
      Parameters:
      gap - the gap value (e.g., "8px", "0.5rem")
      Returns:
      this TabbedLayout for method chaining
    • setTabBarPadding

      public TabbedLayout setTabBarPadding(int padding)
      Sets padding for the tab bar.
      Parameters:
      padding - the padding in pixels
      Returns:
      this TabbedLayout for method chaining
    • setTabBarPadding

      public TabbedLayout setTabBarPadding(String padding)
      Sets padding for the tab bar.
      Parameters:
      padding - the padding value (e.g., "8px", "0.5rem")
      Returns:
      this TabbedLayout for method chaining
    • setTabBarBackground

      public TabbedLayout setTabBarBackground(String color)
      Sets background color for the tab bar.
      Parameters:
      color - the background color
      Returns:
      this TabbedLayout for method chaining
    • setTabBarBorder

      public TabbedLayout setTabBarBorder(String border)
      Sets a bottom border for the horizontal tab bar.
      Parameters:
      border - the border value (e.g., "1px solid #ddd")
      Returns:
      this TabbedLayout for method chaining
    • setContentPadding

      public TabbedLayout setContentPadding(int padding)
      Sets padding for the content area.
      Parameters:
      padding - the padding in pixels
      Returns:
      this TabbedLayout for method chaining
    • setContentPadding

      public TabbedLayout setContentPadding(String padding)
      Sets padding for the content area.
      Parameters:
      padding - the padding value (e.g., "1rem")
      Returns:
      this TabbedLayout for method chaining
    • setContentBackground

      public TabbedLayout setContentBackground(String color)
      Sets background color for the content area.
      Parameters:
      color - the background color
      Returns:
      this TabbedLayout for method chaining
    • getTabBar

      public Element<?> getTabBar()
      Returns the tab bar element for customization.
      Returns:
      the tab bar (HStack or VStack depending on orientation)
    • getContentArea

      public Div getContentArea()
      Returns the content area element for customization.
      Returns:
      the content area div
    • setTabBarWidth

      public TabbedLayout setTabBarWidth(int width)
      Sets the tab bar width (for vertical orientation).
      Parameters:
      width - the width in pixels
      Returns:
      this TabbedLayout for method chaining
    • setTabBarWidth

      public TabbedLayout setTabBarWidth(String width)
      Sets the tab bar width (for vertical orientation).
      Parameters:
      width - the width value (e.g., "200px", "20%")
      Returns:
      this TabbedLayout for method chaining