I have a TabLayoutPanel. At the beginning, TabLayoutPanel has no Tab. Users can add as many tabs into it as they can. They can also remove all the tabs.
My requirement is:
I want to set button enabled = true whenever the TabLayoutPanel has at least 1 tab. If it has no tab, then set button enabled = false.
getView().getMainTabLayoutPanel().addAttachHandler(new AttachEvent.Handler(){
@Override
public void onAttachOrDetach(AttachEvent event) {
int currentSelectedTabInt=getView().getMainTabLayoutPanel().getSelectedIndex();
if(currentSelectedTabInt>-1){
getView().getMyButton().setEnabled(true);
}
}
});
The above code doesn't work.
So how to fire an event whenever a tab got inserted into or got removed out of TabLayoutPanel in Gwt?
You can set button enabled = true or false on the handler wherein you listens to the event of buttons AddTabButton and RemoveTabButton. You have to check there the number of tabs visible/present.
myTabLayoutPanel.getWidgetCount(); //Returns the number of tabs and widgets.