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.ResizeComposite
           ↳ com.google.gwt.user.client.ui.TabLayoutPanel

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 text, HTML, or widgets.

This widget will only work in standards mode, which requires that the HTML page in which it is run have an explicit <!DOCTYPE> declaration.

CSS Style Rules

.gwt-TabLayoutPanel
the panel itself
.gwt-TabLayoutPanel .gwt-TabLayoutPanelTabs
the tab bar element
.gwt-TabLayoutPanel .gwt-TabLayoutPanelTab
an individual tab
.gwt-TabLayoutPanel .gwt-TabLayoutPanelTabInner
an element nested in each tab (useful for styling)
.gwt-TabLayoutPanel .gwt-TabLayoutPanelContent
applied to all child content widgets

Example

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

Use in UiBinder Templates

A TabLayoutPanel element in a UiBinder template must have a barHeight attribute with a double value, and may have a barUnit attribute with a Style.Unit value. barUnit defaults to PX.

The children of a TabLayoutPanel element are laid out in <g:tab> elements. Each tab can have one widget child and one of two types of header elements. A <g:header> element can hold html, or a <g:customHeader> element can hold a widget. (Note that the tags of the header elements are not capitalized. This is meant to signal that the head is not a runtime object, and so cannot have a ui:field attribute.)

For example:

 <g:TabLayoutPanel barUnit='EM' barHeight='3'>
  <g:tab>
    <g:header size='7'><b>HTML</b> header</g:header>
    <g:Label>able</g:Label>
  </g:tab>
  <g:tab>
    <g:customHeader size='7'>
      <g:Label>Custom header</g:Label>
    </g:customHeader>
    <g:Label>baker</g:Label>
  </g:tab>
 </g:TabLayoutPanel>
 

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
TabLayoutPanel(double barHeight, Style.Unit barUnit)
Creates an empty tab panel.
Public Methods
void add(IsWidget w, String text, boolean asHtml)
Convenience overload to allow IsWidget to be used directly.
void add(Widget child, Widget tab)
Adds a widget to the panel.
void add(Widget child, String text, boolean asHtml)
Adds a widget to the panel.
void add(IsWidget w, IsWidget tab)
Convenience overload to allow IsWidget to be used directly.
void add(Widget w)
Adds a child widget.
void add(Widget child, SafeHtml html)
Adds a widget to the panel.
void add(IsWidget w, String text)
Convenience overload to allow IsWidget to be used directly.
void add(Widget child, String text)
Adds a widget to the panel.
void add(IsWidget w)
Convenience overload to allow IsWidget to be used directly.
HandlerRegistration addBeforeSelectionHandler(BeforeSelectionHandler<Integer> handler)
HandlerRegistration addSelectionHandler(SelectionHandler<Integer> handler)
void clear()
Removes all child widgets.
int getSelectedIndex()
Gets the index of the currently-selected tab.
Widget getTabWidget(Widget child)
Gets the widget in the tab associated with the given child widget.
Widget getTabWidget(int index)
Gets the widget in the tab at the given index.
Widget getTabWidget(IsWidget child)
Convenience overload to allow IsWidget to be used directly.
Widget getWidget(int index)
Returns the widget at the given index.
int getWidgetCount()
Returns the number of tabs and widgets.
int getWidgetIndex(IsWidget child)
Convenience overload to allow IsWidget to be used directly.
int getWidgetIndex(Widget child)
Returns the index of the given child, or -1 if it is not a child.
void insert(Widget child, String text, int beforeIndex)
Inserts a widget into the panel.
void insert(IsWidget child, IsWidget tab, int beforeIndex)
Convenience overload to allow IsWidget to be used directly.
void insert(IsWidget child, String text, boolean asHtml, int beforeIndex)
Convenience overload to allow IsWidget to be used directly.
void insert(Widget child, Widget tab, int beforeIndex)
Inserts a widget into the panel.
void insert(IsWidget child, int beforeIndex)
Convenience overload to allow IsWidget to be used directly.
void insert(IsWidget child, String text, int beforeIndex)
Convenience overload to allow IsWidget to be used directly.
void insert(Widget child, SafeHtml html, int beforeIndex)
Inserts a widget into the panel.
void insert(Widget child, int beforeIndex)
Inserts a widget into the panel.
void insert(Widget child, String text, boolean asHtml, int beforeIndex)
Inserts a widget into the panel.
Iterator<Widget> iterator()
Gets an iterator for the contained widgets.
boolean remove(Widget w)
Removes a child widget.
boolean remove(int index)
Removes the widget at the specified index.
void selectTab(Widget child, boolean fireEvents)
Programmatically selects the specified tab.
void selectTab(int index)
Programmatically selects the specified tab and fires events.
void selectTab(IsWidget child)
Convenience overload to allow IsWidget to be used directly.
void selectTab(Widget child)
Programmatically selects the specified tab and fires events.
void selectTab(IsWidget child, boolean fireEvents)
Convenience overload to allow IsWidget to be used directly.
void selectTab(int index, boolean fireEvents)
Programmatically selects the specified tab.
void setTabHTML(int index, String html)
Sets a tab's HTML contents.
void setTabHTML(int index, SafeHtml html)
Sets a tab's HTML contents.
void setTabText(int index, String text)
Sets a tab's text contents.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.ResizeComposite
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.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.RequiresResize
From interface java.lang.Iterable

Public Constructors

public TabLayoutPanel (double barHeight, Style.Unit barUnit)

Creates an empty tab panel.

Parameters
barHeight the size of the tab bar
barUnit the unit in which the tab bar size is specified

Public Methods

public void add (IsWidget w, String text, boolean asHtml)

Convenience overload to allow IsWidget to be used directly.

public void add (Widget child, Widget tab)

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

Parameters
child the widget to be added
tab the widget to be placed in the associated tab

public void add (Widget child, String text, boolean asHtml)

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

Parameters
child the widget to be added
text the text to be shown on its tab
asHtml true to treat the specified text as HTML

public void add (IsWidget w, IsWidget tab)

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 (Widget child, SafeHtml html)

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

Parameters
child the widget to be added
html the html to be shown on its tab

public void add (IsWidget w, String text)

Convenience overload to allow IsWidget to be used directly.

public void add (Widget child, String text)

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

Parameters
child the widget to be added
text the text to be shown on its tab

public void add (IsWidget w)

Convenience overload to allow IsWidget to be used directly.

public HandlerRegistration addBeforeSelectionHandler (BeforeSelectionHandler<Integer> handler)

public HandlerRegistration addSelectionHandler (SelectionHandler<Integer> handler)

public void clear ()

Removes all child widgets.

public int getSelectedIndex ()

Gets the index of the currently-selected tab.

Returns
  • the selected index, or -1 if none is selected.

public Widget getTabWidget (Widget child)

Gets the widget in the tab associated with the given child widget.

Parameters
child the child whose tab is to be retrieved
Returns
  • the tab's widget

public Widget getTabWidget (int index)

Gets the widget in the tab at the given index.

Parameters
index the index of the tab to be retrieved
Returns
  • the tab's widget

public Widget getTabWidget (IsWidget child)

Convenience overload to allow IsWidget to be used directly.

public Widget getWidget (int index)

Returns the widget at the given index.

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

public int getWidgetCount ()

Returns the number of tabs and widgets.

Returns
  • the number of children

public int getWidgetIndex (IsWidget child)

Convenience overload to allow IsWidget to be used directly.

public int getWidgetIndex (Widget child)

Returns the index of the given child, or -1 if it is not a child.

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

public void insert (Widget child, String text, int beforeIndex)

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

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

public void insert (IsWidget child, IsWidget tab, int beforeIndex)

Convenience overload to allow IsWidget to be used directly.

public void insert (IsWidget child, String text, boolean asHtml, int beforeIndex)

Convenience overload to allow IsWidget to be used directly.

public void insert (Widget child, Widget tab, int beforeIndex)

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

Parameters
child the widget to be added
tab the widget to be placed in the associated tab
beforeIndex the index before which it will be inserted

public void insert (IsWidget child, int beforeIndex)

Convenience overload to allow IsWidget to be used directly.

public void insert (IsWidget child, String text, int beforeIndex)

Convenience overload to allow IsWidget to be used directly.

public void insert (Widget child, SafeHtml html, int beforeIndex)

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

Parameters
child the widget to be added
html the html to be shown on its tab
beforeIndex the index before which it will be inserted

public void insert (Widget child, int beforeIndex)

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

Parameters
child the widget to be added
beforeIndex the index before which it will be inserted

public void insert (Widget child, String text, boolean asHtml, int beforeIndex)

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

Parameters
child the widget to be added
text 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 Iterator<Widget> iterator ()

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

public boolean remove (Widget w)

Removes a child widget.

Parameters
w 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 selectTab (Widget child, boolean fireEvents)

Programmatically selects the specified tab.

Parameters
child the child whose tab is to be selected
fireEvents true to fire events, false not to

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 (IsWidget child)

Convenience overload to allow IsWidget to be used directly.

public void selectTab (Widget child)

Programmatically selects the specified tab and fires events.

Parameters
child the child whose tab is to be selected

public void selectTab (IsWidget child, boolean fireEvents)

Convenience overload to allow IsWidget to be used directly.

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 setTabHTML (int index, String html)

Sets a tab's HTML contents. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using setTabHTML(int, SafeHtml) or setTabText(int, String) whenever possible.

Parameters
index the index of the tab whose HTML is to be set
html the tab's new HTML contents

public void setTabHTML (int index, SafeHtml html)

Sets a tab's HTML contents.

Parameters
index the index of the tab whose HTML is to be set
html the tab's new HTML contents

public void setTabText (int index, String text)

Sets a tab's text contents.

Parameters
index the index of the tab whose text is to be set
text the object's new text