Search code examples
javagwtgxt

Ext GWT 2.2.6 :TabIndex of the selected tab in tabpanel


I am trying to create an listener for tabpanel on Onselect event when a tab is selected. And I using below code.

It always alerts as -1, when any tab is selected. Can anyone please suggest any input on this.

eventTab.addListener(Events.Select, new Listener<TabPanelEvent>() {
              public void handleEvent(TabPanelEvent be) { 
                       Window.alert(" selected tab index is"+be.getSelectedItem().getTabIndex()); 
                       } 
       });

Solution

  • GWT - You can get selected tab by using addSelectionHandler. Try this code,

    tabPanel.addSelectionHandler(new SelectionHandler<Integer>(){
      public void onSelection(SelectionEvent<Integer> event){
       int tabId = event.getSelectedItem();
       Widget tabWidget = tabpanel.getWidget(tabId);
     }
    });
    

    GWT EXT

        eventTab.addListener(Events.Select, new Listener<ComponentEvent>() {
          public void handleEvent(ComponentEvent be) {
             Window.alert(" selected tab index is"+ be.getTabIndex());
          }
        });