Class TabSheet

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.tabs.TabSheet
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasSize, HasStyle, HasTheme, HasPrefix, HasSuffix, HasThemeVariant<TabSheetVariant>, Serializable

@Tag("vaadin-tabsheet") @NpmPackage(value="@vaadin/tabsheet", version="24.1.0") @JsModule("@vaadin/tabsheet/src/vaadin-tabsheet.js") public class TabSheet extends Component implements HasPrefix, HasStyle, HasSize, HasSuffix, HasThemeVariant<TabSheetVariant>
TabSheet consists of a set of tabs and the content area. The content area displays a component associated with the selected tab.
Author:
Vaadin Ltd.
See Also:
  • Constructor Details

    • TabSheet

      public TabSheet()
      The default constructor.
  • Method Details

    • add

      public Tab add(String tabText, Component content)
      Adds a tab created from the given text and content.
      Parameters:
      tabText - the text of the tab
      content - the content related to the tab
      Returns:
      the created tab
    • add

      public Tab add(Component tabContent, Component content)
      Adds a tab created from the given tab content and content.
      Parameters:
      tabContent - the content of the tab
      content - the content related to the tab
      Returns:
      the created tab
    • add

      public Tab add(Tab tab, Component content)
      Adds a tab with the given content.
      Parameters:
      tab - the tab
      content - the content related to the tab
      Returns:
      the added tab
    • add

      public Tab add(Tab tab, Component content, int position)
      Adds a tab with the given content to the given position.
      Parameters:
      tab - the tab
      content - the content related to the tab
      position - the position where the tab should be added. If negative, the tab is added at the end.
      Returns:
      the added tab
    • remove

      public void remove(Tab tab)
      Removes a tab.
      Parameters:
      tab - the non-null tab to be removed
    • remove

      public void remove(Component content)
      Removes a tab based on the content
      Parameters:
      content - the non-null content related to the tab to be removed
    • remove

      public void remove(int position)
      Removes the tab at the given position.
      Parameters:
      position - the position of the tab to be removed
    • getSelectedIndex

      public int getSelectedIndex()
      Gets the zero-based index of the currently selected tab.
      Returns:
      the zero-based index of the selected tab, or -1 if none of the tabs is selected
    • setSelectedIndex

      public void setSelectedIndex(int selectedIndex)
      Selects a tab based on its zero-based index.
      Parameters:
      selectedIndex - the zero-based index of the selected tab, -1 to unselect all
    • getSelectedTab

      public Tab getSelectedTab()
      Gets the currently selected tab.
      Returns:
      the selected tab, or null if none is selected
    • setSelectedTab

      public void setSelectedTab(Tab selectedTab)
      Selects the given tab.
      Parameters:
      selectedTab - the tab to select, null to unselect all
      Throws:
      IllegalArgumentException - if selectedTab is not a child of this component
    • getTabAt

      public Tab getTabAt(int position)
      Returns the tab at the given position.
      Parameters:
      position - the position of the tab, must be greater than or equals to 0 and less than the number of tabs
      Returns:
      The tab at the given index
      Throws:
      IllegalArgumentException - if the index is less than 0 or greater than or equals to the number of tabs
    • getIndexOf

      public int getIndexOf(Tab tab)
      Returns the index of the given tab.
      Parameters:
      tab - the tab to look up, can not be null
      Returns:
      the index of the tab or -1 if the tab is not added
    • getTab

      public Tab getTab(Component content)
      Returns the Tab associated with the given component.
      Parameters:
      content - the component to look up, can not be null
      Returns:
      The tab instance associated with the given component, or null if the TabSheet does not contain the component.
    • getComponent

      public Component getComponent(Tab tab)
      Returns the Component instance associated with the given tab.
      Parameters:
      tab - the tab to look up, can not be null
      Returns:
      The component instance associated with the given tab, or null if the TabSheet does not contain the tab.
    • addSelectedChangeListener

      public Registration addSelectedChangeListener(ComponentEventListener<TabSheet.SelectedChangeEvent> listener)
      Adds a listener for TabSheet.SelectedChangeEvent.
      Parameters:
      listener - the listener to add, not null
      Returns:
      a handle that can be used for removing the listener