Removing all but current tab from tabbedpane
In order to remove all other tabs except the currently selected tab in a JTabbedPane,
I wrote this code:
if(actionCommand.equals("Close Other Tabs"))
int selectedIndex = tabbedPane.getSelectedIndex();
for(int i = 0; i < tabbedPane.getTabCount(); i++)
if(selectedIndex != i) // if tab is not 'selected', then remove it
The problem is that though some tabs duly get removed, other unselected tabs fail to get removed and remain along with the currently selected tab. Thanks.