tags:

views:

92

answers:

2

Hi ,

I have created a Tab panel where additional tabs can be added on clicking a button.

What I cannot figure out is how to remove a tab that is not the one that was added last.

Here's where I am....

TabPanel tp = new TabPanel(); HorizontalPanel tabPanel = new HorizontalPanel(); Label textLabel = new Label("Some Filename"); Button killButton = new Button("x");

tabPanel.add(textLabel); tabPanel.add(killButton);

tp.add(new HTML("Some Content"), tabPanel);//Body and header

killButton.addClickHandler( new ClickHandler(){ public void onClick(ClickEvent event){

  //Decide the Tab index that contains this button
  //Remove this tab based on index

} });//End of addClickHandler method

When I try to use the getWidgetIndex() method to return the index of a particular tab I get -1 everytime.

How do I correctly return an index of a tab?

please help as I am going insane!!!

:-(

A: 

getWidgetIndex needs the content widget instead of the tab widget as argument. So for example in your case that would be the widget created with new HTML("Some Content").

Hilbrand
+3  A: 

Hi there, to remove a tab you need either a reference to the Widget you added as the content of the tab, or you need the tab index for the tab you need to remove. Part of your above example would be like

final TabPanel tp = new TabPanel();
final HTML someContent1 = new HTML("Page A");
...
public void onClick(ClickEvent event){
  tp.remove(someContent1);
  // or just remove the tab it self
  //tp.getTabBar().removeTab(0);
}

NingZhang.info

Ning120