Class EnhancedTabs

All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasEnabled, HasSize, HasStyle, Serializable

@JsModule("./fcEnhancedTabs/connector.js") @CssImport("./fcEnhancedTabs/fc-enhanced-tabs.css") @CssImport("./fcEnhancedTabs/fc-enhanced-tabs-legacy.css") @CssImport(value="./fcEnhancedTabs/vaadin-menu-bar-button-legacy.css",themeFor="vaadin-menu-bar-button") public class EnhancedTabs extends Composite<MenuBar> implements HasEnabled, HasSize, HasStyle
Tabs are used to organize and group content into sections that the user can navigate between. Use Tabs when you want to allow in-place navigation within a certain part of the UI, instead of showing everything at once or forcing the user to navigate between different views.

Tab components can be added to this component with the add(Tab...) method or the Tabs(Tab...) constructor. The Tab components added to it can be selected with the setSelectedIndex(int) or setSelectedTab(Tab) methods. The first added Tab component will be automatically selected, firing a EnhancedTabs.SelectedChangeEvent, unless autoselection is explicitly disabled with Tabs(boolean, Tab...), or setAutoselect(boolean). Removing the selected tab from the component changes the selection to the next available tab.

Note: Adding or removing Tab components via the Element API, eg. tabs.getElement().insertChild(0, tab.getElement()); , doesn't update the selected index, so it may cause the selected tab to change unexpectedly.

See Also:
  • Constructor Details

    • EnhancedTabs

      public EnhancedTabs()
      Constructs an empty new object.
    • EnhancedTabs

      public EnhancedTabs(Tab... tabs)
      Constructs a new object enclosing the given tabs.

      The first added Tab component will be automatically selected. Any selection change listener added afterwards will not be notified about the auto-selected tab.

      Parameters:
      tabs - the tabs to enclose
    • EnhancedTabs

      public EnhancedTabs(boolean autoselect, Tab... tabs)
      Constructs a new object enclosing the given autoselect option and tabs,.

      Unless auto-select is disabled, the first added Tab component will be automatically selected. Any selection change listener added afterwards will not be notified about the auto-selected tab.

      Parameters:
      autoselect - true to automatically select the first added tab, false to leave tabs unselected
      tabs - the tabs to enclose
  • Method Details

    • onAttach

      protected void onAttach(AttachEvent event)
      Overrides:
      onAttach in class Component
    • setOpenOnHover

      public void setOpenOnHover(boolean openOnHover)
      Sets whether the submenu opens by clicking or hovering on the overflow buttons. Defaults to true.
      Parameters:
      openOnHover - true to make the sub menus open on hover (mouseover), false to make them openable by clicking
    • isOpenOnHover

      public boolean isOpenOnHover()
      Gets whether the submenu opens by clicking or hovering on the overflow buttons.
      Returns:
      true if the sub menus open by hovering on the root level buttons, false if they open by clicking
    • add

      public void add(Tab... tabs)
      Adds the given tabs to the component.

      The first added Tab component will be automatically selected, unless auto-selection is explicitly disabled with Tabs(boolean, Tab...), or setAutoselect(boolean). If a selection change listener has been added before adding the tabs, it will be notified with the auto-selected tab.

      Parameters:
      tabs - the tabs to enclose
    • addRouterLink

      public RouterLink addRouterLink(String text, Class<? extends Component> target)
    • remove

      public void remove(Tab... tabs)
      Removes the given child tabs from this component.
      Parameters:
      tabs - the tabs to remove
      Throws:
      IllegalArgumentException - if there is a tab whose non null parent is not this component

      Removing tabs before the selected tab will decrease the selected index to avoid changing the selected tab. Removing the selected tab will select the next available tab if autoselect is true, otherwise no tab will be selected.

    • removeAll

      public void removeAll()
      Removes all tabs from this component. It also removes the children that were added only at the client-side.

      This will reset the selected index to zero.

    • replace

      public void replace(Tab oldTab, Tab newTab)
      Replaces the tab in the container with another one without changing position. This method replaces tab with another one is such way that the new tab overtakes the position of the old tab. If the old tab is not in the container, the new tab is added to the container. If the both tabs are already in the container, their positions are swapped. Tab attach and detach events should be taken care as with add and remove.
      Parameters:
      oldTab - the old tab that will be replaced. Can be null, which will make the newTab to be added to the layout without replacing any other
      newTab - the new tab to be replaced. Can be null, which will make the oldTab to be removed from the layout without adding any other

      Replacing the currently selected tab will make the new tab selected.

    • addSelectedChangeListener

      public Registration addSelectedChangeListener(ComponentEventListener<EnhancedTabs.SelectedChangeEvent> listener)
      Parameters:
      listener - the listener to add, not null
      Returns:
      a handle that can be used for removing the listener
    • 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
    • setSelectedTab

      public void setSelectedTab(Tab selectedTab, boolean changedFromClient)
    • setAutoselect

      public void setAutoselect(boolean autoselect)
      Specify that the tabs should be automatically selected. When autoselect is false, no tab will be selected when the component load and it will not select any others tab when removing currently selected tab. The default value is true.
      Parameters:
      autoselect - true to autoselect tab, false to not.
    • isAutoselect

      public boolean isAutoselect()
      Gets whether the tabs should be automatically selected. The default value is true.
      Returns:
      true if autoselect is active, false otherwise
      See Also:
    • indexOf

      public int indexOf(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 a child
    • getComponentCount

      public int getComponentCount()
      Gets the number of children tabs.
      Returns:
      the number of tabs
    • getTabAt

      public Tab getTabAt(int index)
      Returns the tab at the given position.
      Parameters:
      index - the position of the tab, must be greater than or equals to 0 and less than the number of children 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 children tabs
    • getTabCount

      public int getTabCount()
    • getTabs

      public Stream<Tab> getTabs()