java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.Composite
         ↳ com.google.gwt.user.client.ui.TabPanel
Known Direct Subclasses

Class Overview

A panel that represents a tabbed set of pages, each of which contains another widget. Its child widgets are shown as the user selects the various tabs associated with them. The tabs can contain arbitrary HTML.

This widget will only work in quirks mode. If your application is in Standards Mode, use TabLayoutPanel instead.

Note that this widget is not a panel per se, but rather a Composite that aggregates a TabBar and a DeckPanel. It does, however, implement HasWidgets.

CSS Style Rules

  • .gwt-TabPanel { the tab panel itself }
  • .gwt-TabPanelBottom { the bottom section of the tab panel (the deck containing the widget) }

Example

{@example com.google.gwt.examples.TabPanelExample}

See Also

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
TabPanel()
Creates an empty tab panel.
Public Methods
void add(IsWidget w, String tabText, boolean asHTML)
Convenience overload to allow IsWidget to be used directly.
void add(Widget w, Widget tabWidget)
Adds a widget to the tab panel.
void add(Widget w, String tabText, boolean asHTML)
Adds a widget to the tab panel.
void add(IsWidget w, IsWidget tabWidget)
Convenience overload to allow IsWidget to be used directly.
void add(Widget w)
Adds a child widget.
void add(IsWidget w, String tabText)
Convenience overload to allow IsWidget to be used directly.
void add(Widget w, String tabText)
Adds a widget to the tab panel.
HandlerRegistration addBeforeSelectionHandler(BeforeSelectionHandler<Integer> handler)
HandlerRegistration addSelectionHandler(SelectionHandler<Integer> handler)
void addTabListener(TabListener listener)
void clear()
Removes all child widgets.
DeckPanel getDeckPanel()
Gets the deck panel within this tab panel.
TabBar getTabBar()
Gets the tab bar within this tab panel.
Widget getWidget(int index)
Gets the child widget at the specified index.
int getWidgetCount()
Gets the number of child widgets in this panel.
int getWidgetIndex(IsWidget child)
Convenience overload to allow IsWidget to be used directly.
int getWidgetIndex(Widget widget)
Gets the index of the specified child widget.
void insert(IsWidget widget, IsWidget tabWidget, int beforeIndex)
Convenience overload to allow IsWidget to be used directly.
void insert(Widget widget, String tabText, int beforeIndex)
Inserts a widget into the tab panel.
void insert(IsWidget widget, String tabText, boolean asHTML, int beforeIndex)
Convenience overload to allow IsWidget to be used directly.
void insert(Widget widget, Widget tabWidget, int beforeIndex)
Inserts a widget into the tab panel.
void insert(IsWidget widget, String tabText, int beforeIndex)
Convenience overload to allow IsWidget to be used directly.
void insert(Widget widget, String tabText, boolean asHTML, int beforeIndex)
Inserts a widget into the tab panel.
boolean isAnimationEnabled()
Returns true if animations are enabled, false if not.
Iterator<Widget> iterator()
Gets an iterator for the contained widgets.
boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex)
This method is deprecated. Use onBeforeSelection(BeforeSelectionEvent) instead
void onTabSelected(SourcesTabEvents sender, int tabIndex)
This method is deprecated. Use onSelection(SelectionEvent) instead
boolean remove(Widget widget)
Removes the given widget, and its associated tab.
boolean remove(int index)
Removes the widget at the specified index.
void removeTabListener(TabListener listener)
This method is deprecated. Use the removeHandler() method on the object returned by and add*Handler method instead
void selectTab(int index)
Programmatically selects the specified tab and fires events.
void selectTab(int index, boolean fireEvents)
Programmatically selects the specified tab.
void setAnimationEnabled(boolean enable)
Enable or disable animations.
Protected Methods
SimplePanel createTabTextWrapper()
Create a SimplePanel that will wrap the contents in a tab.
void onEnsureDebugId(String baseID)
Affected Elements:
  • -bar = The tab bar.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.Composite
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.logical.shared.HasBeforeSelectionHandlers
From interface com.google.gwt.event.logical.shared.HasSelectionHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.HasAnimation
From interface com.google.gwt.user.client.ui.HasWidgets
From interface com.google.gwt.user.client.ui.IndexedPanel
From interface com.google.gwt.user.client.ui.IndexedPanel.ForIsWidget
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesTabEvents
From interface com.google.gwt.user.client.ui.TabListener
From interface java.lang.Iterable

Public Constructors

public TabPanel ()

Creates an empty tab panel.

Public Methods

public void add (IsWidget w, String tabText, boolean asHTML)

Convenience overload to allow IsWidget to be used directly.

public void add (Widget w, Widget tabWidget)

Adds a widget to the tab panel. If the Widget is already attached to the TabPanel, it will be moved to the right-most index.

Parameters
w the widget to be added
tabWidget the widget to be shown in the tab

public void add (Widget w, String tabText, boolean asHTML)

Adds a widget to the tab panel. If the Widget is already attached to the TabPanel, it will be moved to the right-most index.

Parameters
w the widget to be added
tabText the text to be shown on its tab
asHTML true to treat the specified text as HTML

public void add (IsWidget w, IsWidget tabWidget)

Convenience overload to allow IsWidget to be used directly.

public void add (Widget w)

Adds a child widget.

Parameters
w the widget to be added

public void add (IsWidget w, String tabText)

Convenience overload to allow IsWidget to be used directly.

public void add (Widget w, String tabText)

Adds a widget to the tab panel. If the Widget is already attached to the TabPanel, it will be moved to the right-most index.

Parameters
w the widget to be added
tabText the text to be shown on its tab

public HandlerRegistration addBeforeSelectionHandler (BeforeSelectionHandler<Integer> handler)

public HandlerRegistration addSelectionHandler (SelectionHandler<Integer> handler)

public void addTabListener (TabListener listener)

This method is deprecated.
Use addBeforeSelectionHandler(BeforeSelectionHandler) and addSelectionHandler(SelectionHandler) instead

Adds a listener interface to receive click events.

Parameters
listener the listener interface to add

public void clear ()

Removes all child widgets.

public DeckPanel getDeckPanel ()

Gets the deck panel within this tab panel. Adding or removing Widgets from the DeckPanel is not supported and will throw UnsupportedOperationExceptions.

Returns
  • the deck panel

public TabBar getTabBar ()

Gets the tab bar within this tab panel. Adding or removing tabs from from the TabBar is not supported and will throw UnsupportedOperationExceptions.

Returns
  • the tab bar

public Widget getWidget (int index)

Gets the child widget at the specified index.

Parameters
index the child widget's index
Returns
  • the child widget

public int getWidgetCount ()

Gets the number of child widgets in this panel.

Returns
  • the number of children

public int getWidgetIndex (IsWidget child)

Convenience overload to allow IsWidget to be used directly.

public int getWidgetIndex (Widget widget)

Gets the index of the specified child widget.

Parameters
widget the widget to be found
Returns
  • the widget's index, or -1 if it is not a child of this panel

public void insert (IsWidget widget, IsWidget tabWidget, int beforeIndex)

Convenience overload to allow IsWidget to be used directly.

public void insert (Widget widget, String tabText, int beforeIndex)

Inserts a widget into the tab panel. If the Widget is already attached to the TabPanel, it will be moved to the requested index.

Parameters
widget the widget to be inserted
tabText the text to be shown on its tab
beforeIndex the index before which it will be inserted

public void insert (IsWidget widget, String tabText, boolean asHTML, int beforeIndex)

Convenience overload to allow IsWidget to be used directly.

public void insert (Widget widget, Widget tabWidget, int beforeIndex)

Inserts a widget into the tab panel. If the Widget is already attached to the TabPanel, it will be moved to the requested index.

Parameters
widget the widget to be inserted.
tabWidget the widget to be shown on its tab.
beforeIndex the index before which it will be inserted.

public void insert (IsWidget widget, String tabText, int beforeIndex)

Convenience overload to allow IsWidget to be used directly.

public void insert (Widget widget, String tabText, boolean asHTML, int beforeIndex)

Inserts a widget into the tab panel. If the Widget is already attached to the TabPanel, it will be moved to the requested index.

Parameters
widget the widget to be inserted
tabText the text to be shown on its tab
asHTML true to treat the specified text as HTML
beforeIndex the index before which it will be inserted

public boolean isAnimationEnabled ()

Returns true if animations are enabled, false if not.

public Iterator<Widget> iterator ()

Gets an iterator for the contained widgets. This iterator is required to implement remove().

public boolean onBeforeTabSelected (SourcesTabEvents sender, int tabIndex)

This method is deprecated.
Use onBeforeSelection(BeforeSelectionEvent) instead

Fired just before a tab is selected.

Parameters
sender the TabBar or TabPanel whose tab was selected.
tabIndex the index of the tab about to be selected
Returns
  • false to disallow the selection. If any listener returns false, then the selection will be disallowed.

public void onTabSelected (SourcesTabEvents sender, int tabIndex)

This method is deprecated.
Use onSelection(SelectionEvent) instead

Fired when a tab is selected.

Parameters
sender the TabBar or TabPanel whose tab was selected
tabIndex the index of the tab that was selected

public boolean remove (Widget widget)

Removes the given widget, and its associated tab.

Parameters
widget the widget to be removed
Returns
  • true if the widget was present

public boolean remove (int index)

Removes the widget at the specified index.

Parameters
index the index of the widget to be removed
Returns
  • false if the widget is not present

public void removeTabListener (TabListener listener)

This method is deprecated.
Use the removeHandler() method on the object returned by and add*Handler method instead

Removes a previously added listener interface.

Parameters
listener the listener interface to remove

public void selectTab (int index)

Programmatically selects the specified tab and fires events.

Parameters
index the index of the tab to be selected

public void selectTab (int index, boolean fireEvents)

Programmatically selects the specified tab.

Parameters
index the index of the tab to be selected
fireEvents true to fire events, false not to

public void setAnimationEnabled (boolean enable)

Enable or disable animations.

Parameters
enable true to enable, false to disable

Protected Methods

protected SimplePanel createTabTextWrapper ()

Create a SimplePanel that will wrap the contents in a tab. Subclasses can use this method to wrap tabs in decorator panels.

Returns
  • a SimplePanel to wrap the tab contents, or null to leave tabs unwrapped

protected void onEnsureDebugId (String baseID)

Affected Elements:

  • -bar = The tab bar.
  • -bar-tab# = The element containing the content of the tab itself.
  • -bar-tab-wrapper# = The cell containing the tab at the index.
  • -bottom = The panel beneath the tab bar.

Parameters
baseID the base ID used by the main element