## com.google.gwt.user.client.ui
Class TabBar

    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

All Implemented Interfaces:
  EventListener, ClickListener, KeyboardListener, SourcesTabEvents

Direct Known Subclasses:
  DecoratedTabBar

    public class TabBar

extends Composite
implements SourcesTabEvents, ClickListener, KeyboardListener

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-TabBarRest { the right edge of the bar }
- .gwt-TabBar .gwt-TabBarItem { unselected tabs }
- .gwt-TabBar .gwt-TabBarItem-wrapper { table cell around tab }
- .gwt-TabBar .gwt-TabBarItem-selected { additional style for selected tabs }
- .gwt-TabBar .gwt-TabBarItem-wrapper-selected { table cell around selected tab }

### Example

>     public class TabBarExample implements EntryPoint {

>       public void onModuleLoad() {
>         // Create a tab bar with three items.
>         TabBar bar = new TabBar();
>         bar.addTab("foo");
>         bar.addTab("bar");
>         bar.addTab("baz");

>         // Hook up a tab listener to do something when the user selects a tab.
>         bar.addTabListener(new TabListener() {
>           public void onTabSelected(SourcesTabEvents sender, int tabIndex) {
>             // Let the user know what they just did.
>             Window.alert("You clicked tab " + tabIndex);
>           }

>           public boolean onBeforeTabSelected(SourcesTabEvents sender,
>               int tabIndex) {

>             // Just for fun, let's disallow selection of 'bar'.
>             if (tabIndex == 1)
>               return false;
>             return true;
>           }
>         });

>         // Add it to the root panel.
>         RootPanel.get().add(bar);
>       }
>     }

Nested Class Summary

Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
`UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled`

Field Summary

Fields inherited from class com.google.gwt.user.client.ui.UIObject
`DEBUG_ID_PREFIX`

Fields inherited from interface com.google.gwt.user.client.ui.KeyboardListener
`KEY_ALT, KEY_BACKSPACE, KEY_CTRL, KEY_DELETE, KEY_DOWN, KEY_END, KEY_ENTER, KEY_ESCAPE, KEY_HOME, KEY_LEFT, KEY_PAGEDOWN, KEY_PAGEUP, KEY_RIGHT, KEY_SHIFT, KEY_TAB, KEY_UP, MODIFIER_ALT, MODIFIER_CTRL, MODIFIER_META, MODIFIER_SHIFT`

Constructor Summary
`TabBar()` Creates an empty tab bar.

Method Summary
`void` `addTab(java.lang.String text)` Adds a new tab with the specified text.
`void` `addTab(java.lang.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` `addTabListener(TabListener listener)` Adds a listener interface to receive click events.
`protected SimplePanel` `createTabTextWrapper()` Create a `SimplePanel` that will wrap the contents in a tab.
`int` `getSelectedTab()` Gets the tab that is currently selected.
`int` `getTabCount()` Gets the number of tabs present.
`java.lang.String` `getTabHTML(int index)` Gets the specified tab's HTML.
`void` `insertTab(java.lang.String text, boolean asHTML, int beforeIndex)` Inserts a new tab at the specified index.
`void` `insertTab(java.lang.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.
`protected void` `insertTabWidget(Widget widget, int beforeIndex)` Inserts a new tab at the specified index.
`void` `onClick(Widget sender)` Fired when the user clicks on a widget.
`protected void` `onEnsureDebugId(java.lang.String baseID)` Affected Elements: -tab# = The element containing the contents of the tab. -tab-wrapper# = The cell containing the tab at the index.
`void` `onKeyDown(Widget sender, char keyCode, int modifiers)` Fired when the user depresses a physical key.
`void` `onKeyPress(Widget sender, char keyCode, int modifiers)` Fired when a keyboard action generates a character.
`void` `onKeyUp(Widget sender, char keyCode, int modifiers)` Fired when the user releases a physical key.
`void` `removeTab(int index)` Removes the tab at the specified index.
`void` `removeTabListener(TabListener listener)` Removes a previously added listener interface.
`boolean` `selectTab(int index)` Programmatically selects the specified tab.

Methods inherited from class com.google.gwt.user.client.ui.Composite
`getWidget, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, setWidget`

Methods inherited from class com.google.gwt.user.client.ui.Widget
`doAttachChildren, doDetachChildren, getParent, onLoad, onUnload, removeFromParent`

Methods inherited from class com.google.gwt.user.client.ui.UIObject

`addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### TabBar

    public TabBar()

  Creates an empty tab bar.

Method Detail

### addTab

    public void addTab(java.lang.String text)

  Adds a new tab with the specified text.

  Parameters:
    `text` - the new tab's text

### addTab

    public void addTab(java.lang.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

### addTab

    public void addTab(Widget widget)

  Adds a new tab with the specified widget.

  Parameters:
    `widget` - the new tab's widget.

### addTabListener

    public void addTabListener(TabListener listener)

  Description copied from interface: `SourcesTabEvents`
  Adds a listener interface to receive click events.

  Specified by:
    `addTabListener` in interface `SourcesTabEvents`
  Parameters:
    `listener` - the listener interface to add

### getSelectedTab

    public int getSelectedTab()

  Gets the tab that is currently selected.

  Returns:
    the selected tab

### getTabCount

    public int getTabCount()

  Gets the number of tabs present.

  Returns:
    the tab count

### getTabHTML

    public java.lang.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

### insertTab

    public void insertTab(java.lang.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

### insertTab

    public void insertTab(java.lang.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

### insertTab

    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.

### onClick

    public void onClick(Widget sender)

  Description copied from interface: `ClickListener`
  Fired when the user clicks on a widget.

  Specified by:
    `onClick` in interface `ClickListener`
  Parameters:
    `sender` - the widget sending the event.

### onKeyDown

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

  Description copied from interface: `KeyboardListener`
  Fired when the user depresses a physical key.

  Specified by:
    `onKeyDown` in interface `KeyboardListener`
  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 `KeyboardListener.MODIFIER_SHIFT`, `KeyboardListener.MODIFIER_CTRL`, and `KeyboardListener.MODIFIER_ALT`.

### onKeyPress

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

  Description copied from interface: `KeyboardListener`
  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 `KeyboardListener.KEY_ENTER` or arrow keys. These keyCodes can be reliably captured either with `KeyboardListener.onKeyDown(Widget, char, int)` or `KeyboardListener.onKeyUp(Widget, char, int)`.

  Specified by:
    `onKeyPress` in interface `KeyboardListener`
  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 `KeyboardListener.MODIFIER_SHIFT`, `KeyboardListener.MODIFIER_CTRL`, and `KeyboardListener.MODIFIER_ALT`.

### onKeyUp

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

  Description copied from interface: `KeyboardListener`
  Fired when the user releases a physical key.

  Specified by:
    `onKeyUp` in interface `KeyboardListener`
  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 `KeyboardListener.MODIFIER_SHIFT`, `KeyboardListener.MODIFIER_CTRL`, and `KeyboardListener.MODIFIER_ALT`.

### removeTab

    public void removeTab(int index)

  Removes the tab at the specified index.

  Parameters:
    `index` - the index of the tab to be removed

### removeTabListener

    public void removeTabListener(TabListener listener)

  Description copied from interface: `SourcesTabEvents`
  Removes a previously added listener interface.

  Specified by:
    `removeTabListener` in interface `SourcesTabEvents`
  Parameters:
    `listener` - the listener interface to remove

### selectTab

    public boolean selectTab(int index)

  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.
  Returns:
    `true` if successful, `false` if the change is denied by the `TabListener`.

### createTabTextWrapper

    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

### insertTabWidget

    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.

### onEnsureDebugId

    protected void onEnsureDebugId(java.lang.String baseID)

  Affected Elements:
  - -tab# = The element containing the contents of the tab.
  - -tab-wrapper# = The cell containing the tab at the index.

  Overrides:
    `onEnsureDebugId` in class `UIObject`
  Parameters:
    `baseID` - the base ID used by the main element
  See Also:
    `UIObject.onEnsureDebugId(String)`