Class TabBar

public class TabBar
extends Composite
implements SourcesTabEvents, ClickListener
A horizontal bar of folder-style tabs, most commonly used as part of a TabPanel.

CSS Style Rules

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);
  }
}

Constructors

TabBar()Creates an empty tab bar.

Methods

addTab(String)Adds a new tab with the specified text.
addTab(String, boolean)Adds a new tab with the specified text.
addTab(Widget)Adds a new tab with the specified widget.
addTabListener(TabListener)Adds a listener interface to receive click events.
getSelectedTab()Gets the tab that is currently selected.
getTabCount()Gets the number of tabs present.
getTabHTML(int)Gets the specified tab's HTML.
insertTab(String, boolean, int)Inserts a new tab at the specified index.
insertTab(String, int)Inserts a new tab at the specified index.
insertTab(Widget, int)Inserts a new tab at the specified index.
onClick(Widget)Fired when the user clicks on a widget.
removeTab(int)Removes the tab at the specified index.
removeTabListener(TabListener)Removes a previously added listener interface.
selectTab(int)Programmatically selects the specified tab.

Constructor Detail

TabBar

public TabBar()
Creates an empty tab bar.

Method Detail

addTab

public void addTab(String text)
Adds a new tab with the specified text.

Parameters

text
the new tab's text

addTab

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

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)
Adds a listener interface to receive click events.

Parameters

listener
the listener interface to add

getSelectedTab

public int getSelectedTab()
Gets the tab that is currently selected.

Return Value

the selected tab

getTabCount

public int getTabCount()
Gets the number of tabs present.

Return Value

the tab count

getTabHTML

public String getTabHTML(int index)
Gets the specified tab's HTML.

Parameters

index
the index of the tab whose HTML is to be retrieved

Return Value

the tab's HTML

insertTab

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

insertTab

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

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)
Fired when the user clicks on a widget.

Parameters

sender
the widget sending the event.

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)
Removes a previously added listener interface.

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.

Return Value

true if successful, false if the change is denied by the TabListener.