com.vaadin.ui.
Class TabSheet
java.lang.Object
com.vaadin.ui.AbstractComponent
com.vaadin.ui.AbstractComponentContainer
com.vaadin.ui.TabSheet
All Implemented Interfaces:
FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, MethodEventSource, Paintable, Sizeable, VariableOwner, Component, Component.Focusable, ComponentContainer, Serializable, EventListener
Direct Known Subclasses:
- extends AbstractComponentContainer
- implements Component.Focusable, FieldEvents.FocusNotifier, FieldEvents.BlurNotifier
public class TabSheet
TabSheet component.
Tabs are typically identified by the component contained on the tab (see
ComponentContainer
), and tab metadata (including caption, icon,
visibility, enabledness, closability etc.) is kept in separate TabSheet.Tab
instances.
Tabs added with addComponent(Component)
get the caption and the icon
of the component at the time when the component is created, and these are not
automatically updated after tab creation.
A tab sheet can have multiple tab selection listeners and one tab close
handler (TabSheet.CloseHandler
), which by default removes the tab from the
TabSheet.
The TabSheet
can be styled with the .v-tabsheet, .v-tabsheet-tabs and
.v-tabsheet-content styles. Themes may also have pre-defined variations of
the tab sheet presentation, such as Reindeer.TABSHEET_BORDERLESS
,
Runo.TABSHEET_SMALL
and several other styles in Reindeer
.
The current implementation does not load the tabs to the UI before the first
time they are shown, but this may change in future releases.
Since:
3.0
Version:
6.8.18
Author:
Vaadin Ltd.
See Also:
Nested Class Summary | |
---|---|
static interface |
TabSheet.CloseHandler
CloseHandler is used to process tab closing events. |
class |
TabSheet.SelectedTabChangeEvent
Selected tab change event. |
static interface |
TabSheet.SelectedTabChangeListener
Selected tab change event listener. |
static interface |
TabSheet.Tab
Tab meta-data for a component in a TabSheet . |
class |
TabSheet.TabSheetTabImpl
TabSheet's implementation of TabSheet.Tab - tab metadata. |
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent |
---|
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler |
Nested classes/interfaces inherited from interface com.vaadin.ui.Component |
---|
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener |
Nested classes/interfaces inherited from interface com.vaadin.terminal.Paintable |
---|
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener |
Nested classes/interfaces inherited from interface com.vaadin.ui.ComponentContainer |
---|
ComponentContainer.ComponentAttachEvent, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachEvent, ComponentContainer.ComponentDetachListener |
Field Summary |
---|
Fields inherited from interface com.vaadin.terminal.Sizeable |
---|
SIZE_UNDEFINED, UNIT_SYMBOLS, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS |
Constructor Summary | |
---|---|
TabSheet()
Constructs a new Tabsheet. |
Method Summary | |
---|---|
void |
addComponent(Component c)
Adds a new tab into TabSheet. |
void |
addListener(FieldEvents.BlurListener listener)
Adds a BlurListener to the Component which gets fired
when a Field loses keyboard focus. |
void |
addListener(FieldEvents.FocusListener listener)
Adds a FocusListener to the Component which gets fired
when a Field receives keyboard focus. |
void |
addListener(TabSheet.SelectedTabChangeListener listener)
Adds a tab selection listener |
TabSheet.Tab |
addTab(Component c)
Adds a new tab into TabSheet. |
TabSheet.Tab |
addTab(Component c,
int position)
Adds a new tab into TabSheet. |
TabSheet.Tab |
addTab(Component c,
String caption)
Adds a new tab into TabSheet. |
TabSheet.Tab |
addTab(Component c,
String caption,
Resource icon)
Adds a new tab into TabSheet. |
TabSheet.Tab |
addTab(Component c,
String caption,
Resource icon,
int position)
Adds a new tab into TabSheet. |
boolean |
areTabsHidden()
Are the tab selection parts ("tabs") hidden. |
void |
changeVariables(Object source,
Map<String,Object> variables)
Called when one or more variables handled by the implementing class are changed. |
protected void |
fireSelectedTabChange()
Sends an event that the currently selected tab has changed. |
void |
focus()
Sets the focus for this component if the component is Focusable . |
int |
getComponentCount()
Gets the number of contained components (tabs). |
Iterator<Component> |
getComponentIterator()
Gets the component container iterator for going through all the components (tab contents). |
Component |
getSelectedTab()
Gets the selected tab content component. |
TabSheet.Tab |
getTab(Component c)
Returns the TabSheet.Tab (metadata) for a component. |
TabSheet.Tab |
getTab(int position)
Returns the TabSheet.Tab (metadata) for a component. |
String |
getTabCaption(Component c)
Deprecated. Use getTab(Component) and TabSheet.Tab.getCaption()
instead. |
Resource |
getTabIcon(Component c)
Deprecated. Use getTab(Component) and TabSheet.Tab.getIcon()
instead. |
int |
getTabIndex()
Gets the tabulator index of the Focusable component. |
int |
getTabPosition(TabSheet.Tab tab)
Gets the position of the tab |
void |
hideTabs(boolean tabsHidden)
Hides or shows the tab selection parts ("tabs"). |
void |
moveComponentsFrom(ComponentContainer source)
Moves all components from another container to this container. |
void |
paintContent(PaintTarget target)
Paints the content of this component. |
void |
removeComponent(Component c)
Removes a component and its corresponding tab. |
void |
removeListener(FieldEvents.BlurListener listener)
Removes a BlurListener from the Component. |
void |
removeListener(FieldEvents.FocusListener listener)
Removes a FocusListener from the Component. |
void |
removeListener(Paintable.RepaintRequestListener listener)
Removes repaint request listener. |
void |
removeListener(TabSheet.SelectedTabChangeListener listener)
Removes a tab selection listener |
void |
removeTab(TabSheet.Tab tab)
Removes a TabSheet.Tab and the component associated with it, as previously
added with addTab(Component) ,
addTab(Component, String, Resource) or
addComponent(Component) . |
void |
replaceComponent(Component oldComponent,
Component newComponent)
Replaces a component (tab content) with another. |
void |
setCloseHandler(TabSheet.CloseHandler handler)
Provide a custom TabSheet.CloseHandler for this TabSheet if you wish to
perform some additional tasks when a user clicks on a tabs close button,
e.g. |
void |
setSelectedTab(Component c)
Sets the selected tab. |
void |
setSelectedTab(int position)
Sets the selected tab, identified by its position. |
void |
setSelectedTab(TabSheet.Tab tab)
Sets the selected tab. |
void |
setTabCaption(Component c,
String caption)
Deprecated. Use getTab(Component) and
TabSheet.Tab.setCaption(String) instead. |
void |
setTabIcon(Component c,
Resource icon)
Deprecated. Use getTab(Component) and
TabSheet.Tab.setIcon(Resource) instead. |
void |
setTabIndex(int tabIndex)
Sets the tabulator index of the Focusable component. |
void |
setTabPosition(TabSheet.Tab tab,
int position)
Sets the position of the tab. |
Methods inherited from class com.vaadin.ui.AbstractComponentContainer |
---|
addListener, addListener, attach, detach, fireComponentAttachEvent, fireComponentDetachEvent, removeAllComponents, removeListener, removeListener, requestRepaintAll, setEnabled, setHeight, setWidth |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.vaadin.ui.Component |
---|
addListener, addStyleName, attach, childRequestedRepaint, detach, getApplication, getCaption, getIcon, getLocale, getParent, getStyleName, getWindow, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setParent, setReadOnly, setStyleName, setVisible |
Methods inherited from interface com.vaadin.terminal.Paintable |
---|
addListener, getDebugId, paint, requestRepaint, requestRepaintRequests, setDebugId |
Methods inherited from interface com.vaadin.terminal.VariableOwner |
---|
isImmediate |
Methods inherited from interface com.vaadin.terminal.Sizeable |
---|
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeight, setHeightUnits, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidth, setWidthUnits |
Constructor Detail |
---|
TabSheet
public TabSheet()
Constructs a new Tabsheet. Tabsheet is immediate by default, and the default close handler removes the tab being closed.
Method Detail |
---|
getComponentIterator
public Iterator<Component> getComponentIterator()
- Specified by:
getComponentIterator
in interfaceComponentContainer
- Returns:
- the unmodifiable Iterator of the tab content components
Gets the component container iterator for going through all the components (tab contents).
getComponentCount
public int getComponentCount()
- Returns:
- the number of contained components
Gets the number of contained components (tabs). Consistent with the
iterator returned by getComponentIterator()
.
removeComponent
public void removeComponent(Component c)
- Specified by:
removeComponent
in interfaceComponentContainer
- Overrides:
removeComponent
in classAbstractComponentContainer
- Parameters:
c
- the component to be removed.- See Also:
ComponentContainer.removeComponent(Component)
Removes a component and its corresponding tab. If the tab was selected, the first eligible (visible and enabled) remaining tab is selected.
removeTab
public void removeTab(TabSheet.Tab tab)
- Parameters:
tab
- the Tab to remove- See Also:
addTab(Component)
,addTab(Component, String, Resource)
,addComponent(Component)
,removeComponent(Component)
Removes a TabSheet.Tab
and the component associated with it, as previously
added with addTab(Component)
,
addTab(Component, String, Resource)
or
addComponent(Component)
.
If the tab was selected, the first eligible (visible and enabled) remaining tab is selected.
addComponent
public void addComponent(Component c)
- Specified by:
addComponent
in interfaceComponentContainer
- Overrides:
addComponent
in classAbstractComponentContainer
- Parameters:
c
- the component to be added.- See Also:
addTab(Component)
Adds a new tab into TabSheet. Component caption and icon are copied to the tab metadata at creation time.
addTab
public TabSheet.Tab addTab(Component c,
String caption)
- Parameters:
c
- the component to be added onto tab - should not be null.caption
- the caption to be set for the component and used rendered in tab bar- Returns:
- the created
TabSheet.Tab
Adds a new tab into TabSheet. The first tab added to a tab sheet is automatically selected and a tab selection event is fired. If the component is already present in the tab sheet, changes its caption and returns the corresponding (old) tab, preserving other tab metadata.
addTab
public TabSheet.Tab addTab(Component c,
String caption,
Resource icon)
- Parameters:
c
- the component to be added onto tab - should not be null.caption
- the caption to be set for the component and used rendered in tab baricon
- the icon to be set for the component and used rendered in tab bar- Returns:
- the created
TabSheet.Tab
Adds a new tab into TabSheet. The first tab added to a tab sheet is automatically selected and a tab selection event is fired. If the component is already present in the tab sheet, changes its caption and icon and returns the corresponding (old) tab, preserving other tab metadata.
addTab
public TabSheet.Tab addTab(Component c,
String caption,
Resource icon,
int position)
- Parameters:
c
- the component to be added onto tab - should not be null.caption
- the caption to be set for the component and used rendered in tab baricon
- the icon to be set for the component and used rendered in tab barposition
- the position at where the the tab should be added.- Returns:
- the created
TabSheet.Tab
Adds a new tab into TabSheet. The first tab added to a tab sheet is automatically selected and a tab selection event is fired. If the component is already present in the tab sheet, changes its caption and icon and returns the corresponding (old) tab, preserving other tab metadata like the position.
addTab
public TabSheet.Tab addTab(Component c)
- Parameters:
c
- the component to be added onto tab - should not be null.- Returns:
- the created
TabSheet.Tab
Adds a new tab into TabSheet. Component caption and icon are copied to the tab metadata at creation time. If the tab sheet already contains the component, its tab is returned.
addTab
public TabSheet.Tab addTab(Component c,
int position)
- Parameters:
c
- the component to be added onto tab - should not be null.position
- The position where the tab should be added- Returns:
- the created
TabSheet.Tab
Adds a new tab into TabSheet. Component caption and icon are copied to the tab metadata at creation time. If the tab sheet already contains the component, its tab is returned.
moveComponentsFrom
public void moveComponentsFrom(ComponentContainer source)
- Specified by:
moveComponentsFrom
in interfaceComponentContainer
- Overrides:
moveComponentsFrom
in classAbstractComponentContainer
- Parameters:
source
- the container components are removed from.
Moves all components from another container to this container. The
components are removed from the other container.
If the source container is a TabSheet
, component captions and
icons are copied from it.
paintContent
public void paintContent(PaintTarget target)
throws PaintException
- Overrides:
paintContent
in classAbstractComponent
- Parameters:
target
- the paint target- Throws:
PaintException
- if the paint operation failed.
Paints the content of this component.
areTabsHidden
public boolean areTabsHidden()
- Returns:
- true if the tabs are hidden in the UI
Are the tab selection parts ("tabs") hidden.
hideTabs
public void hideTabs(boolean tabsHidden)
- Parameters:
tabsHidden
- true if the tabs should be hidden
Hides or shows the tab selection parts ("tabs").
getTabCaption
@Deprecated
public String getTabCaption(Component c)
- Parameters:
c
- the component in the tab
Deprecated. Use getTab(Component)
and TabSheet.Tab.getCaption()
instead.
Gets tab caption. The tab is identified by the tab content component.
setTabCaption
@Deprecated
public void setTabCaption(Component c,
String caption)
- Parameters:
c
- the component in the tabcaption
- the caption to set.
Deprecated. Use getTab(Component)
and
TabSheet.Tab.setCaption(String)
instead.
Sets tab caption. The tab is identified by the tab content component.
getTabIcon
@Deprecated
public Resource getTabIcon(Component c)
- Parameters:
c
- the component in the tab
Deprecated. Use getTab(Component)
and TabSheet.Tab.getIcon()
instead.
Gets the icon for a tab. The tab is identified by the tab content component.
setTabIcon
@Deprecated
public void setTabIcon(Component c,
Resource icon)
- Parameters:
c
- the component in the tabicon
- the icon to set
Deprecated. Use getTab(Component)
and
TabSheet.Tab.setIcon(Resource)
instead.
Sets icon for the given component. The tab is identified by the tab content component.
getTab
public TabSheet.Tab getTab(Component c)
- Parameters:
c
- the component- Returns:
- The tab instance associated with the given component, or null if the tabsheet does not contain the component.
Returns the TabSheet.Tab
(metadata) for a component. The TabSheet.Tab
object can be used for setting caption,icon, etc for the tab.
getTab
public TabSheet.Tab getTab(int position)
- Parameters:
position
- the position of the tab- Returns:
- The tab in the given position, or null if the position is out of bounds.
Returns the TabSheet.Tab
(metadata) for a component. The TabSheet.Tab
object can be used for setting caption,icon, etc for the tab.
setSelectedTab
public void setSelectedTab(Component c)
- Parameters:
c
-
Sets the selected tab. The tab is identified by the tab content component. Does nothing if the tabsheet doesn't contain the component.
setSelectedTab
public void setSelectedTab(TabSheet.Tab tab)
- Parameters:
tab
-
Sets the selected tab. The tab is identified by the corresponding
Tab
instance. Does nothing if the tabsheet doesn't contain
the given tab.
setSelectedTab
public void setSelectedTab(int position)
- Parameters:
position
-
Sets the selected tab, identified by its position. Does nothing if the position is out of bounds.
getSelectedTab
public Component getSelectedTab()
- Returns:
- the selected tab contents
Gets the selected tab content component.
changeVariables
public void changeVariables(Object source,
Map<String,Object> variables)
- Specified by:
changeVariables
in interfaceVariableOwner
- Overrides:
changeVariables
in classAbstractComponent
- Parameters:
source
- the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.variables
- the Mapping from variable names to new variable values.
Description copied from interface: VariableOwner
Called when one or more variables handled by the implementing class are changed.
replaceComponent
public void replaceComponent(Component oldComponent,
Component newComponent)
- Specified by:
replaceComponent
in interfaceComponentContainer
- Parameters:
oldComponent
- the old component that will be replaced.newComponent
- the new component to be replaced.
Replaces a component (tab content) with another. This can be used to
change tab contents or to rearrange tabs. The tab position and some
metadata are preserved when moving components within the same
TabSheet
.
If the oldComponent is not present in the tab sheet, the new one is added
at the end.
If the oldComponent is already in the tab sheet but the newComponent
isn't, the old tab is replaced with a new one, and the caption and icon
of the old one are copied to the new tab.
If both old and new components are present, their positions are swapped.
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.
addListener
public void addListener(TabSheet.SelectedTabChangeListener listener)
- Parameters:
listener
- the Listener to be added.
Adds a tab selection listener
removeListener
public void removeListener(TabSheet.SelectedTabChangeListener listener)
- Parameters:
listener
- the Listener to be removed.
Removes a tab selection listener
fireSelectedTabChange
protected void fireSelectedTabChange()
Sends an event that the currently selected tab has changed.
removeListener
public void removeListener(Paintable.RepaintRequestListener listener)
- Specified by:
removeListener
in interfacePaintable
- Overrides:
removeListener
in classAbstractComponent
- Parameters:
listener
- the listener to be removed.
Description copied from interface: Paintable
Removes repaint request listener.
setCloseHandler
public void setCloseHandler(TabSheet.CloseHandler handler)
- Parameters:
handler
-
Provide a custom TabSheet.CloseHandler
for this TabSheet if you wish to
perform some additional tasks when a user clicks on a tabs close button,
e.g. show a confirmation dialogue before removing the tab.
To remove the tab, if you provide your own close handler, you must call
removeComponent(Component)
yourself.
The default CloseHandler for TabSheet will only remove the tab.
setTabPosition
public void setTabPosition(TabSheet.Tab tab,
int position)
- Parameters:
tab
- The tabposition
- The new position of the tab
Sets the position of the tab.
getTabPosition
public int getTabPosition(TabSheet.Tab tab)
- Parameters:
tab
- The tab- Returns:
Gets the position of the tab
focus
public void focus()
- Specified by:
focus
in interfaceComponent.Focusable
- Overrides:
focus
in classAbstractComponent
Description copied from class: AbstractComponent
Sets the focus for this component if the component is Focusable
.
getTabIndex
public int getTabIndex()
- Specified by:
getTabIndex
in interfaceComponent.Focusable
- Returns:
- tab index set for the
Focusable
component - See Also:
Component.Focusable.setTabIndex(int)
Description copied from interface: Component.Focusable
Gets the tabulator index of the Focusable
component.
setTabIndex
public void setTabIndex(int tabIndex)
- Specified by:
setTabIndex
in interfaceComponent.Focusable
- Parameters:
tabIndex
- the tab order of this component. Indexes usually start from 1. Zero means that default tab order should be used. A negative value means that the field should not be included in the tabbing sequence.- See Also:
Component.Focusable.getTabIndex()
Description copied from interface: Component.Focusable
Sets the tabulator index of the Focusable
component.
The tab index property is used to specify the order in which the
fields are focused when the user presses the Tab key. Components with
a defined tab index are focused sequentially first, and then the
components with no tab index.
Form loginBox = new Form();
loginBox.setCaption("Login");
layout.addComponent(loginBox);
// Create the first field which will be focused
TextField username = new TextField("User name");
loginBox.addField("username", username);
// Set focus to the user name
username.focus();
TextField password = new TextField("Password");
loginBox.addField("password", password);
Button login = new Button("Login");
loginBox.getFooter().addComponent(login);
// An additional component which natural focus order would
// be after the button.
CheckBox remember = new CheckBox("Remember me");
loginBox.getFooter().addComponent(remember);
username.setTabIndex(1);
password.setTabIndex(2);
remember.setTabIndex(3); // Different than natural place
login.setTabIndex(4);
After all focusable user interface components are done, the browser can begin again from the component with the smallest tab index, or it can take the focus out of the page, for example, to the location bar.
If the tab index is not set (is set to zero), the default tab order is used. The order is somewhat browser-dependent, but generally follows the HTML structure of the page.
A negative value means that the component is completely removed from the tabulation order and can not be reached by pressing the Tab key at all.
addListener
public void addListener(FieldEvents.BlurListener listener)
- Specified by:
addListener
in interfaceFieldEvents.BlurNotifier
- See Also:
FieldEvents.BlurListener
Description copied from interface: FieldEvents.BlurNotifier
Adds a BlurListener
to the Component which gets fired
when a Field
loses keyboard focus.
removeListener
public void removeListener(FieldEvents.BlurListener listener)
- Specified by:
removeListener
in interfaceFieldEvents.BlurNotifier
- See Also:
FieldEvents.BlurListener
Description copied from interface: FieldEvents.BlurNotifier
Removes a BlurListener
from the Component.
addListener
public void addListener(FieldEvents.FocusListener listener)
- Specified by:
addListener
in interfaceFieldEvents.FocusNotifier
- See Also:
FieldEvents.FocusListener
Description copied from interface: FieldEvents.FocusNotifier
Adds a FocusListener
to the Component which gets fired
when a Field
receives keyboard focus.
removeListener
public void removeListener(FieldEvents.FocusListener listener)
- Specified by:
removeListener
in interfaceFieldEvents.FocusNotifier
- See Also:
FieldEvents.FocusListener
Description copied from interface: FieldEvents.FocusNotifier
Removes a FocusListener
from the Component.