public class Tabs extends GeneratedVaadinTabs<Tabs> implements HasOrderedComponents<Tabs>, HasSize
vaadin-tabs
element.
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.
Modifier and Type | Class and Description |
---|---|
static class |
Tabs.Orientation
The valid orientations of
Tabs instances. |
static class |
Tabs.SelectedChangeEvent
An event to mark that the selected tab has changed.
|
Constructor and Description |
---|
Tabs()
Constructs an empty new object with
HORIZONTAL orientation. |
Tabs(boolean autoselect,
Tab... tabs)
Constructs a new object enclosing the given autoselect option and tabs,
with
HORIZONTAL orientation. |
Tabs(Tab... tabs)
Constructs a new object enclosing the given tabs, with
HORIZONTAL orientation. |
Modifier and Type | Method and Description |
---|---|
void |
add(Component... components)
Adds the given components as children of this component.
|
void |
add(Tab... tabs)
Adds the given tabs to the component.
|
void |
addComponentAtIndex(int index,
Component component)
Adds the given component as child of this component at the specific
index.
|
Registration |
addSelectedChangeListener(ComponentEventListener<Tabs.SelectedChangeEvent> listener)
Adds a listener for
Tabs.SelectedChangeEvent . |
Tabs.Orientation |
getOrientation()
Gets the orientation of this tab sheet.
|
int |
getSelectedIndex()
Gets the zero-based index of the currently selected tab.
|
Tab |
getSelectedTab()
Gets the currently selected tab.
|
boolean |
isAutoselect()
Gets whether the tabs should be automatically selected.
|
protected void |
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
|
void |
remove(Component... components)
Removes the given child components from this component.
|
void |
removeAll()
Removes all contents from this component, this includes child components,
text content as well as child elements that have been added directly to
this component using the
Element API. |
void |
replace(Component oldComponent,
Component newComponent)
Replaces the component in the container with another one without changing
position.
|
void |
setAutoselect(boolean autoselect)
Specify that the tabs should be automatically selected.
|
void |
setFlexGrowForEnclosedTabs(double flexGrow)
Sets the flex grow property of all enclosed tabs.
|
void |
setOrientation(Tabs.Orientation orientation)
Sets the orientation of this tab sheet.
|
void |
setSelectedIndex(int selectedIndex)
Selects a tab based on its zero-based index.
|
void |
setSelectedTab(Tab selectedTab)
Selects the given tab.
|
addThemeVariants, focus, removeThemeVariants
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getChildren, getComponentAt, getComponentCount, indexOf
add, addComponentAsFirst
isEnabled, setEnabled
getElement
getCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
addAttachListener
addDetachListener
public Tabs()
HORIZONTAL
orientation.public Tabs(Tab... tabs)
HORIZONTAL
orientation.
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)
.
tabs
- the tabs to enclosepublic Tabs(boolean autoselect, Tab... tabs)
HORIZONTAL
orientation.autoselect
- true
to automatically select the first added tab,
false
to leave tabs unselectedtabs
- the tabs to enclosepublic void add(Tab... tabs)
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)
.
tabs
- the tabs to enclosepublic void add(Component... components)
HasComponents
In case the any of the specified components has already been added to another parent, it will be removed from there and added to this one.
add
in interface HasComponents
components
- the components to addpublic void remove(Component... components)
Removing components 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.
remove
in interface HasComponents
components
- the components to removepublic void removeAll()
Element
API. it also removes the
children that were added only at the client-side.
This will reset the selected index
to zero.
removeAll
in interface HasComponents
public void addComponentAtIndex(int index, Component component)
In case the specified component has already been added to another parent, it will be removed from there and added to this one.
Adding a component before the currently selected tab will increment the
selected index
to avoid changing the selected
tab.
addComponentAtIndex
in interface HasComponents
index
- the index, where the component will be added. The index must
be non-negative and may not exceed the children countcomponent
- the component to add, value should not be nullpublic void replace(Component oldComponent, Component newComponent)
Replacing the currently selected tab will make the new tab selected.
replace
in interface HasOrderedComponents<Tabs>
oldComponent
- the old component that will be replaced. Can be
null
, which will make the newComponent to be
added to the layout without replacing any othernewComponent
- the new component to be replaced. Can be null
,
which will make the oldComponent to be removed from the layout
without adding any otherprotected void onAttach(AttachEvent attachEvent)
Component
The default implementation does nothing.
This method is invoked before the AttachEvent
is fired for the
component.
public Registration addSelectedChangeListener(ComponentEventListener<Tabs.SelectedChangeEvent> listener)
Tabs.SelectedChangeEvent
.listener
- the listener to add, not null
@Synchronize(property="selected", value="selected-changed") public int getSelectedIndex()
public void setSelectedIndex(int selectedIndex)
selectedIndex
- the zero-based index of the selected tab, -1 to unselect allpublic Tab getSelectedTab()
null
if none is selectedpublic void setSelectedTab(Tab selectedTab)
selectedTab
- the tab to select, null
to unselect allIllegalArgumentException
- if selectedTab
is not a child of this componentpublic Tabs.Orientation getOrientation()
public void setOrientation(Tabs.Orientation orientation)
orientation
- the orientationpublic void setFlexGrowForEnclosedTabs(double flexGrow)
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.
flexGrow
- the proportion of the available space the enclosed tabs should
take upIllegalArgumentException
- if flexGrow
is negativepublic void setAutoselect(boolean autoselect)
autoselect
- true
to autoselect tab, false
to not.public boolean isAutoselect()
true
if autoselect is active, false
otherwisesetAutoselect(boolean)
Copyright © 2023. All rights reserved.