You can also add to the tabPanel an empty + widget, then add a selectionChangeHandler
on the tabPanel to detect click on the + tab, which add your new tab and select it.
So the +
tab do the job and is never shown:
tabPanel.add(new Label(), "+");
tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {
@Override
public void onSelection(SelectionEvent<Integer> event) {
if (event.getSelectedItem() == tabPanel.getWidgetCount() - 1) {
Widget w = new Label(); // the widget which contains the new tab
tabPanel.insert(w, w.toString(),
tabPanel.getWidgetCount() - 1);
tabPanel.selectTab(w);
}
}
});