I have a JTabPanel with three tabs, two of which start disabled. I want enable them when they have been given content (otherwise some of the fields and boxes are blank and/or meaningless).
It seems the only way to set whether a tab is enabled or disabled is to pass setEnabledAt an int for the tab index and the boolean. The only way I can find to pass the index of a tab to something is to use indexOfTabComponent and pass in the panel to swap to….This seems horrible, and doesn’t work. I’m getting java.lang.ArrayIndexOutOfBoundsException: -1 when I try and swap to the tab at index 1.
Is there a better way than this?
public void swapView(JPanel paneToSelect) {
myContainerPane.getMyPaneTab().setSelectedComponent(paneToSelect);
myContainerPane.getMyPaneTab().setEnabledAt(myContainerPane.getMyPaneTab().indexOfTabComponent(paneToSelect), true);
}
The only solution I can think of is to add 2 to the index number…but it feels there should be a better way to do this.
The correct code to use is:
The difference being is that, for whatever reason
indexOfTabComponent, does not work with my set up.