com.vaadin.flow.component.tabs.
Class Tabs
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.tabs.GeneratedVaadinTabs<Tabs>
-
- com.vaadin.flow.component.tabs.Tabs
-
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasComponents, HasElement, HasEnabled, HasOrderedComponents<Tabs>, HasSize, HasStyle, Serializable
public class Tabs extends GeneratedVaadinTabs<Tabs> implements HasOrderedComponents<Tabs>, HasSize
Server-side component for the
vaadin-tabs
element.Tab
components can be added to this component with theadd(Tab...)
method or theTabs(Tab...)
constructor. The Tab components added to it can be selected with thesetSelectedIndex(int)
orsetSelectedTab(Tab)
methods. 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 Classes 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 Summary
Constructors Constructor and Description Tabs()
Constructs an empty new object with
HORIZONTAL
orientation.Tabs(Tab... tabs)
Constructs a new object enclosing the given tabs, with
HORIZONTAL
orientation.
-
Method Summary
All Methods 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.
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.
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
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.
-
Methods inherited from class com.vaadin.flow.component.tabs.GeneratedVaadinTabs
focus
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.HasOrderedComponents
getComponentAt, getComponentCount, indexOf
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getWidth, setHeight, setSizeFull, setSizeUndefined, setWidth
-
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
Constructor Detail
-
Tabs
public Tabs()
Constructs an empty new object with
HORIZONTAL
orientation.
-
Tabs
public Tabs(Tab... tabs)
Constructs a new object enclosing the given tabs, with
HORIZONTAL
orientation.Parameters:
tabs
- the tabs to enclose
-
-
Method Detail
-
add
public void add(Tab... tabs)
Adds the given tabs to the component.
Parameters:
tabs
- the tabs to enclose
-
add
public void add(Component... components)
Description copied from interface:
HasComponents
Adds the given components as children of this component.
Specified by:
add
in interfaceHasComponents
Parameters:
components
- the components to add
-
remove
public void remove(Component... components)
Removes the given child components from this component.
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.Specified by:
remove
in interfaceHasComponents
Parameters:
components
- the components to remove
-
removeAll
public 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. it also removes the children that were added only at the client-side.This will reset the
selected index
to zero.Specified by:
removeAll
in interfaceHasComponents
-
replace
public void replace(Component oldComponent, Component newComponent)
Replaces the component in the container with another one without changing position. This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.
Replacing the currently selected tab will make the new tab selected.
Specified by:
replace
in interfaceHasOrderedComponents<Tabs>
Parameters:
oldComponent
- the old component that will be replaced. Can benull
, which will make the newComponent to be added to the layout without replacing any othernewComponent
- the new component to be replaced. Can benull
, which will make the oldComponent to be removed from the layout without adding any other
-
onAttach
protected void onAttach(AttachEvent attachEvent)
Description copied from class:
Component
Called when the component is attached to a UI.
The default implementation does nothing.
This method is invoked before the
AttachEvent
is fired for the component.
-
addSelectedChangeListener
public Registration addSelectedChangeListener(ComponentEventListener<Tabs.SelectedChangeEvent> listener)
Adds a listener for
Tabs.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
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 allThrows:
IllegalArgumentException
- ifselectedTab
is not a child of this component
-
getOrientation
public Tabs.Orientation getOrientation()
Gets the orientation of this tab sheet.
Returns:
the orientation
-
setOrientation
public void setOrientation(Tabs.Orientation orientation)
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 upThrows:
IllegalArgumentException
- ifflexGrow
is negative
-
-