2015-02-11 246 views
1

我想要创建选项卡式页面并在每个选项卡上单击加载不同的信息。使用GWT中的选项卡动态添加选项卡

我希望能够在点击'+'选项卡时动态添加选项卡。 enter image description here

因此,点击'+'后,应将新选项卡添加到同一个tabLayoutPanel。

有关如何在GWT中执行此操作的任何建议。

谢谢。

回答

2
  • 静态添加“+”选项卡(例如,ui xml)。
  • 添加选择处理程序(请参阅In GWT how do I handle the tab click event?了解如何执行此操作)。
  • 在此处理程序中:如果选择了最后一个选项卡,请在其之前插入一个新选项卡并从代码中选择它。
1

你也可以添加到一个tabpanel空+小部件,然后在一个tabpanel添加selectionChangeHandler检测点击+标签,其中添加新的选项卡,并选中它。

所以+标签做的工作,从未显示:

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); 
      } 
     } 
    }); 
相关问题