The GXT toolkit makes it really easy to add or remove a tab from a tab panel. Within code, however, there is a little twist to removing tabs, because in real-world use cases you'll want to do this conditionally. That is, you want to check for a precondition, in the absence of which you will reject or decline, or better still, cancel the request to remove (or close) a tab from its containing TabPanel
object.
To properly see this in action, we will create two buttons, one that the user can click to add a tab and another to remove the currently selected tab (active tab). However, we will prevent the last tab from being removed; that way, our instance of TabPanel
class will always have one tab, at least.
The following code programmatically adds/removes a tab from the instance of TabPanel
class:
final TabPanel tabPanel = new TabPanel(); tabPanel.setHeight(250); tabPanel.setWidth(450); tabPanel.setCloseContextMenu(true); TabItem homeTab = new...