Question

I want to get the tab text when I click on a tab. I do this:

tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {

            @Override
            public void onSelection(SelectionEvent<Integer> event) {
                //get the tabtext here
            }
        });

But I only get the index.

Was it helpful?

Solution

Assuming you are using TabPanel and you haven't provided a custom Widget for the TabBar, you could do this:

tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {

  @Override
  public void onSelection(SelectionEvent<Integer> event) {
      String tabHtml = tabPanel.getTabBar().getTabHTML(event.getSelectedItem());
    }
  });

Of course, you will get the underlying HTML of the tab, that generally is a <div>tab text</div>. The text you put in the add() methods are wrapped in either a Label, or an HTML widget, whether you have chosen to display the tab text as HTML.

Of course this is not handy, generally you need to store somewhere the tab text (in a TabPanel extension I'd guess, or a model) at insertion time (overriding the add(...)s) and retrieve it when needed (by adding a simple getter for them).

OTHER TIPS

You can get the selected tab by following.

tabPanel.getElement().getTitle();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top