开发者

How to kill a Tab in a Tab Panel

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 Clic开发者_JS百科kHandler(){ 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!!!

:-(


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


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").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜