2015-02-11 183 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); 
      } 
     } 
    }); 
相關問題