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.TabBar
Known Direct Subclasses

Class Overview

A horizontal bar of folder-style tabs, most commonly used as part of a TabPanel.

CSS Style Rules

  • .gwt-TabBar { the tab bar itself }
  • .gwt-TabBar .gwt-TabBarFirst { the left edge of the bar }
  • .gwt-TabBar .gwt-TabBarFirst-wrapper { table cell around the left edge }
  • .gwt-TabBar .gwt-TabBarRest { the right edge of the bar }
  • .gwt-TabBar .gwt-TabBarRest-wrapper { table cell around the right edge }
  • .gwt-TabBar .gwt-TabBarItem { unselected tabs }
  • .gwt-TabBar .gwt-TabBarItem-wrapper { table cell around tab }
  • .gwt-TabBar .gwt-TabBarItem-selected { additional style for selected

    Example

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

Summary

Nested Classes
interface TabBar.Tab Set of characteristic interfaces supported by TabBar tabs. 
[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
From interface com.google.gwt.user.client.ui.KeyboardListener
Public Constructors
TabBar()
Creates an empty tab bar.
Public Methods
HandlerRegistration addBeforeSelectionHandler(BeforeSelectionHandler<Integer> handler)
HandlerRegistration addSelectionHandler(SelectionHandler<Integer> handler)
void addTab(SafeHtml html)
Adds a new tab with the specified text.
void addTab(String text, boolean asHTML)
Adds a new tab with the specified text.
void addTab(Widget widget)
Adds a new tab with the specified widget.
void addTab(String text)
Adds a new tab with the specified text.
void addTabListener(TabListener listener)
int getSelectedTab()
Gets the tab that is currently selected.
final TabBar.Tab getTab(int index)
Gets the given tab.
int getTabCount()
Gets the number of tabs present.
String getTabHTML(int index)
Gets the specified tab's HTML.
void insertTab(String text, boolean asHTML, int beforeIndex)
Inserts a new tab at the specified index.
void insertTab(String text, int beforeIndex)
Inserts a new tab at the specified index.
void insertTab(Widget widget, int beforeIndex)
Inserts a new tab at the specified index.
void insertTab(SafeHtml html, int beforeIndex)
Inserts a new tab at the specified index.
boolean isTabEnabled(int index)
Check if a tab is enabled or disabled.
void onClick(Widget sender)
This method is deprecated. add a BeforeSelectionHandler instead. Alternatively, if you need to access to the individual tabs, add a click handler to each TabBar.Tab element instead.
void onKeyDown(Widget sender, char keyCode, int modifiers)
This method is deprecated. add a key down handler to the individual TabBar.Tab objects instead.
void onKeyPress(Widget sender, char keyCode, int modifiers)
This method is deprecated. this method has been doing nothing for the entire last release, if what you wanted to do was to listen to key press events on tabs, add the key press handler to the individual tab wrappers instead.
void onKeyUp(Widget sender, char keyCode, int modifiers)
This method is deprecated. this method has been doing nothing for the entire last release, if what you wanted to do was to listen to key up events on tabs, add the key up handler to the individual tab wrappers instead.
void removeTab(int index)
Removes the tab at the specified index.
void removeTabListener(TabListener listener)
This method is deprecated. Instead use the removeHandler() call on the object returned by an add*Handler method
boolean selectTab(int index)
Programmatically selects the specified tab and fires events.
boolean selectTab(int index, boolean fireEvents)
Programmatically selects the specified tab.
void setTabEnabled(int index, boolean enabled)
Enable or disable a tab.
void setTabHTML(int index, String html)
Sets a tab's contents via HTML.
void setTabHTML(int index, SafeHtml html)
Sets a tab's contents via safe html.
void setTabText(int index, String text)
Sets a tab's text contents.
Protected Methods
SimplePanel createTabTextWrapper()
Create a SimplePanel that will wrap the contents in a tab.
void insertTabWidget(Widget widget, int beforeIndex)
Inserts a new tab at the specified index.
void onEnsureDebugId(String baseID)
Affected Elements:
  • -tab# = The element containing the contents of the tab.
[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.ClickListener
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.KeyboardListener
From interface com.google.gwt.user.client.ui.SourcesTabEvents

Public Constructors

public TabBar ()

Creates an empty tab bar.

Public Methods

public HandlerRegistration addBeforeSelectionHandler (BeforeSelectionHandler<Integer> handler)

public HandlerRegistration addSelectionHandler (SelectionHandler<Integer> handler)

public void addTab (SafeHtml html)

Adds a new tab with the specified text.

Parameters
html the new tab's html

public void addTab (String text, boolean asHTML)

Adds a new tab with the specified text.

Parameters
text the new tab's text
asHTML true to treat the specified text as html

public void addTab (Widget widget)

Adds a new tab with the specified widget.

Parameters
widget the new tab's widget

public void addTab (String text)

Adds a new tab with the specified text.

Parameters
text the new tab's text

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 int getSelectedTab ()

Gets the tab that is currently selected.

Returns
  • the selected tab

public final TabBar.Tab getTab (int index)

Gets the given tab. This method is final because the Tab interface will expand. Therefore it is highly likely that subclasses which implemented this method would end up breaking.

Parameters
index the tab's index
Returns
  • the tab wrapper

public int getTabCount ()

Gets the number of tabs present.

Returns
  • the tab count

public String getTabHTML (int index)

Gets the specified tab's HTML.

Parameters
index the index of the tab whose HTML is to be retrieved
Returns
  • the tab's HTML

public void insertTab (String text, boolean asHTML, int beforeIndex)

Inserts a new tab at the specified index.

Parameters
text the new tab's text
asHTML true to treat the specified text as HTML
beforeIndex the index before which this tab will be inserted

public void insertTab (String text, int beforeIndex)

Inserts a new tab at the specified index.

Parameters
text the new tab's text
beforeIndex the index before which this tab will be inserted

public void insertTab (Widget widget, int beforeIndex)

Inserts a new tab at the specified index.

Parameters
widget widget to be used in the new tab
beforeIndex the index before which this tab will be inserted

public void insertTab (SafeHtml html, int beforeIndex)

Inserts a new tab at the specified index.

Parameters
html the new tab's html
beforeIndex the index before which this tab will be inserted

public boolean isTabEnabled (int index)

Check if a tab is enabled or disabled. If disabled, the user cannot select the tab.

Parameters
index the index of the tab
Returns
  • true if the tab is enabled, false if disabled

public void onClick (Widget sender)

This method is deprecated.
add a BeforeSelectionHandler instead. Alternatively, if you need to access to the individual tabs, add a click handler to each TabBar.Tab element instead.

Fired when the user clicks on a widget.

Parameters
sender the widget sending the event.

public void onKeyDown (Widget sender, char keyCode, int modifiers)

This method is deprecated.
add a key down handler to the individual TabBar.Tab objects instead.

Fired when the user depresses a physical key.

Parameters
sender the widget that was focused when the event occurred.
keyCode the physical key that was depressed. Constants for this value are defined in this interface with the KEY prefix.
modifiers the modifier keys pressed at when the event occurred. This value is a combination of the bits defined by MODIFIER_SHIFT, MODIFIER_CTRL, and MODIFIER_ALT

public void onKeyPress (Widget sender, char keyCode, int modifiers)

This method is deprecated.
this method has been doing nothing for the entire last release, if what you wanted to do was to listen to key press events on tabs, add the key press handler to the individual tab wrappers instead.

Fired when a keyboard action generates a character. This occurs after onKeyDown and onKeyUp are fired for the physical key that was pressed.

It should be noted that many browsers do not generate keypress events for non-printing keyCode values, such as KEY_ENTER or arrow keys. These keyCodes can be reliably captured either with onKeyDown(Widget, char, int) or onKeyUp(Widget, char, int).

Parameters
sender the widget that was focused when the event occurred.
keyCode the Unicode character that was generated by the keyboard action.
modifiers the modifier keys pressed at when the event occurred. This value is a combination of the bits defined by MODIFIER_SHIFT, MODIFIER_CTRL, and MODIFIER_ALT

public void onKeyUp (Widget sender, char keyCode, int modifiers)

This method is deprecated.
this method has been doing nothing for the entire last release, if what you wanted to do was to listen to key up events on tabs, add the key up handler to the individual tab wrappers instead.

Fired when the user releases a physical key.

Parameters
sender the widget that was focused when the event occurred.
keyCode the physical key that was released. Constants for this value are defined in this interface with the KEY prefix.
modifiers the modifier keys pressed at when the event occurred. This value is a combination of the bits defined by MODIFIER_SHIFT, MODIFIER_CTRL, and MODIFIER_ALT

public void removeTab (int index)

Removes the tab at the specified index.

Parameters
index the index of the tab to be removed

public void removeTabListener (TabListener listener)

This method is deprecated.
Instead use the removeHandler() call on the object returned by an add*Handler method

Removes a previously added listener interface.

Parameters
listener the listener interface to remove

public boolean selectTab (int index)

Programmatically selects the specified tab and fires events. Use index -1 to specify that no tab should be selected.

Parameters
index the index of the tab to be selected
Returns

public boolean selectTab (int index, boolean fireEvents)

Programmatically selects the specified tab. Use index -1 to specify that no tab should be selected.

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

public void setTabEnabled (int index, boolean enabled)

Enable or disable a tab. When disabled, users cannot select the tab.

Parameters
index the index of the tab to enable or disable
enabled true to enable, false to disable

public void setTabHTML (int index, String html)

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

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

public void setTabHTML (int index, SafeHtml html)

Sets a tab's contents via safe html.

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

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

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 insertTabWidget (Widget widget, int beforeIndex)

Inserts a new tab at the specified index.

Parameters
widget widget to be used in the new tab
beforeIndex the index before which this tab will be inserted

protected void onEnsureDebugId (String baseID)

Affected Elements:

  • -tab# = The element containing the contents of the tab.
  • -tab-wrapper# = The cell containing the tab at the index.

Parameters
baseID the base ID used by the main element