【问题标题】:Add tab dynamically using a tab item in GWT使用 GWT 中的选项卡项动态添加选项卡
【发布时间】:2015-04-11 13:43:21
【问题描述】:

我想创建一个标签页并在每次点击标签时加载不同的信息。

我希望能够在单击“+”选项卡时动态添加选项卡。

因此,在单击“+”时,应将一个新选项卡添加到同一 tabLayoutPanel。

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

谢谢。

【问题讨论】:

    标签: gwt gwt-tablayoutpanel


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

    【讨论】:

      【解决方案2】:

      您也可以在 tabPanel 中添加一个空的 + 小部件,然后在 tabPanel 上添加一个selectionChangeHandler 以检测对 + 选项卡的点击,从而添加您的新选项卡并选择它。

      所以+tab 完成了这项工作并且从未显示:

          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);
                  }
              }
          });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-10
        • 1970-01-01
        • 2015-09-02
        相关资源
        最近更新 更多