Class Tabs
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,com.vaadin.flow.component.shared.HasThemeVariant<TabsVariant>,Serializable
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
Tabs.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.
- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe valid orientations ofTabsinstances.static classAn event to mark that the selected tab has changed. -
Constructor Summary
ConstructorsConstructorDescriptionTabs()Constructs an empty new object withHORIZONTALorientation.Constructs a new object enclosing the given autoselect option and tabs, withHORIZONTALorientation.Constructs a new object enclosing the given tabs, withHORIZONTALorientation. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(com.vaadin.flow.component.Component... components) Deprecated.voidAdds the given tabs to the component.voidaddComponentAsFirst(com.vaadin.flow.component.Component component) Deprecated.since 24.0, useaddTabAsFirst(Tab)instead.voidaddComponentAtIndex(int index, com.vaadin.flow.component.Component component) Deprecated.since 24.0, useaddTabAtIndex(int, Tab)instead.com.vaadin.flow.shared.RegistrationaddSelectedChangeListener(com.vaadin.flow.component.ComponentEventListener<Tabs.SelectedChangeEvent> listener) Adds a listener forTabs.SelectedChangeEvent.voidaddTabAsFirst(Tab tab) Adds the given tab as the first child of this component.voidaddTabAtIndex(int index, Tab tab) Adds the given tab as child of this tab at the specific index.com.vaadin.flow.component.ComponentgetComponentAt(int index) Deprecated.since 24.0, usegetTabAt(int)instead.intDeprecated.since 24.5, usegetTabCount()instead.Gets the orientation of this tab sheet.intGets the zero-based index of the currently selected tab.Gets the currently selected tab.getTabAt(int index) Returns the tab at the given position.intGets the number of tabs.intindexOf(com.vaadin.flow.component.Component component) Deprecated.since 24.0, useindexOf(Tab)instead.intReturns the index of the given tab.booleanGets whether the tabs should be automatically selected.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) voidremove(com.vaadin.flow.component.Component... components) Deprecated.since 24.0, useremove(Tab...)instead.voidRemoves the given child tabs from this component.voidRemoves all tabs from this component.voidreplace(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent) Deprecated.since 24.0, usereplace(Tab, Tab)instead.voidReplaces the tab in the container with another one without changing position.voidsetAutoselect(boolean autoselect) Specify that the tabs should be automatically selected.voidsetFlexGrowForEnclosedTabs(double flexGrow) Sets the flex grow property of all enclosed tabs.voidsetOrientation(Tabs.Orientation orientation) Sets the orientation of this tab sheet.voidsetSelectedIndex(int selectedIndex) Selects a tab based on its zero-based index.voidsetSelectedTab(Tab selectedTab) Selects the given tab.Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariants
-
Constructor Details
-
Tabs
public Tabs()Constructs an empty new object withHORIZONTALorientation. -
Tabs
Constructs a new object enclosing the given tabs, withHORIZONTALorientation.The first added
Tabcomponent 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
-
Tabs
Constructs a new object enclosing the given autoselect option and tabs, withHORIZONTALorientation.Unless auto-select is disabled, the first added
Tabcomponent will be automatically selected. Any selection change listener added afterwards will not be notified about the auto-selected tab.- Parameters:
autoselect-trueto automatically select the first added tab,falseto leave tabs unselectedtabs- the tabs to enclose
-
-
Method Details
-
add
Deprecated.since 24.0, useadd(Tab...)instead.Adds the given tabs to the component.The first added
Tabcomponent will be automatically selected, unless auto-selection is explicitly disabled withTabs(boolean, Tab...), orsetAutoselect(boolean). If a selection change listener has been added before adding the tabs, it will be notified with the auto-selected tab.- Parameters:
components- the tabs to enclose
-
add
Adds the given tabs to the component.The first added
Tabcomponent will be automatically selected, unless auto-selection is explicitly disabled withTabs(boolean, Tab...), orsetAutoselect(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
-
remove
Deprecated.since 24.0, useremove(Tab...)instead.Removes the given child tabs from this component.- Parameters:
components- the tabs to remove- Throws:
IllegalArgumentException- if there is a tab whose nonnullparent is not this componentRemoving tabs before the selected tab will decrease the
selected indexto 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.
-
remove
Removes the given child tabs from this component.- Parameters:
tabs- the tabs to remove- Throws:
IllegalArgumentException- if there is a tab whose nonnullparent is not this componentRemoving tabs before the selected tab will decrease the
selected indexto 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 indexto zero. -
addComponentAtIndex
@Deprecated public void addComponentAtIndex(int index, com.vaadin.flow.component.Component component) Deprecated.since 24.0, useaddTabAtIndex(int, Tab)instead.Adds the given tab as child of this tab at the specific index.In case the specified tab has already been added to another parent, it will be removed from there and added to this one.
- Parameters:
index- the index, where the tab will be added. The index must be non-negative and may not exceed the children countcomponent- the tab to add, value should not be nullAdding a tab before the currently selected tab will increment the
selected indexto avoid changing the selected tab.
-
addTabAtIndex
Adds the given tab as child of this tab at the specific index.In case the specified tab has already been added to another parent, it will be removed from there and added to this one.
- Parameters:
index- the index, where the tab will be added. The index must be non-negative and may not exceed the children counttab- the tab to add, value should not be nullAdding a tab before the currently selected tab will increment the
selected indexto avoid changing the selected tab.
-
replace
@Deprecated public void replace(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent) Deprecated.since 24.0, usereplace(Tab, Tab)instead.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:
oldComponent- the old tab that will be replaced. Can benull, which will make the newTab to be added to the layout without replacing any othernewComponent- the new tab to be replaced. Can benull, which will make the oldTab to be removed from the layout without adding any otherReplacing the currently selected tab will make the new tab selected.
-
replace
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 benull, which will make the newTab to be added to the layout without replacing any othernewTab- the new tab to be replaced. Can benull, which will make the oldTab to be removed from the layout without adding any otherReplacing the currently selected tab will make the new tab selected.
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) - Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
addSelectedChangeListener
public com.vaadin.flow.shared.Registration addSelectedChangeListener(com.vaadin.flow.component.ComponentEventListener<Tabs.SelectedChangeEvent> listener) Adds a listener forTabs.SelectedChangeEvent.- Parameters:
listener- the listener to add, notnull- Returns:
- a handle that can be used for removing the listener
-
getSelectedIndex
@Synchronize(property="selected", value="selected-changed") 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
Gets the currently selected tab.- Returns:
- the selected tab, or
nullif none is selected
-
setSelectedTab
Selects the given tab.- Parameters:
selectedTab- the tab to select,nullto unselect all- Throws:
IllegalArgumentException- ifselectedTabis not a child of this component
-
getOrientation
Gets the orientation of this tab sheet.- Returns:
- the orientation
-
setOrientation
Sets the orientation of this tab sheet.- Parameters:
orientation- the orientation
-
setFlexGrowForEnclosedTabs
public void setFlexGrowForEnclosedTabs(double flexGrow) Sets the flex grow property of all enclosed tabs. The flex grow property specifies what amount of the available space inside the layout the component should take up, proportionally to the other components.For example, if all components have a flex grow property value set to 1, the remaining space in the layout will be distributed equally to all components inside the layout. If you set a flex grow property of one component to 2, that component will take twice the available space as the other components, and so on.
Setting to flex grow property value 0 disables the expansion of the component. Negative values are not allowed.
- Parameters:
flexGrow- the proportion of the available space the enclosed tabs should take up- Throws:
IllegalArgumentException- ifflexGrowis negative
-
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-trueto autoselect tab,falseto not.
-
isAutoselect
public boolean isAutoselect()Gets whether the tabs should be automatically selected. The default value is true.- Returns:
trueif autoselect is active,falseotherwise- See Also:
-
indexOf
Deprecated.since 24.0, useindexOf(Tab)instead.Returns the index of the given tab.- Parameters:
component- the tab to look up, can not benull- Returns:
- the index of the tab or -1 if the tab is not a child
-
indexOf
Returns the index of the given tab.- Parameters:
tab- the tab to look up, can not benull- Returns:
- the index of the tab or -1 if the tab is not a child
-
getComponentCount
Deprecated.since 24.5, usegetTabCount()instead.Gets the number of children tabs.- Returns:
- the number of tabs
-
getTabCount
public int getTabCount()Gets the number of tabs.- Returns:
- the number of tabs
-
getComponentAt
Deprecated.since 24.0, usegetTabAt(int)instead.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
-
getTabAt
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
-
addComponentAsFirst
Deprecated.since 24.0, useaddTabAsFirst(Tab)instead.Adds the given tab as the first child of this component.In case the specified tab has already been added to another parent, it will be removed from there and added to this one.
- Parameters:
component- the tab to add, value should not be null
-
addTabAsFirst
Adds the given tab as the first child of this component.In case the specified tab has already been added to another parent, it will be removed from there and added to this one.
- Parameters:
tab- the tab to add, value should not be null
-
add(Tab...)instead.