Name: jk109818 Date: 08/12/2003
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OS VERSION :
686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
In JTabbedPane removeTabAt , there is a check that if currently selected index is the last tab, select the previous tab.
But it nowhere checks whether the index i passed in the removeTabAt(int index) method is the selected index.
So if I try to remove a tab which is not the currently selected tab and my currently selected tab is the last tab, I face a problem. My selected tab changes to the second last tab which is not desired.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
revisit the source for removeTabAt(int index) and it should be obvious
The comment there says that if I am removing the currently selected tab, but where does it check that I am deleting the currently selected tab.
public void removeTabAt(int index) {
checkIndex(index);
// If we are removing the currently selected tab AND
// it happens to be the last tab in the bunch, then
// select the previous tab
int tabCount = getTabCount();
int selected = getSelectedIndex();
if (selected >= (tabCount - 1)) {
setSelectedIndexImpl(selected - 1);
}
Component component = getComponentAt(index);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
component, null);
}
// We can't assume the tab indices correspond to the
// container's children array indices, so make sure we
// remove the correct child!
if (component != null) {
Component components[] = getComponents();
for (int i = components.length; --i >= 0; ) {
if (components[i] == component) {
super.remove(i);
component.setVisible(true);
break;
}
}
}
pages.removeElementAt(index);
revalidate();
repaint();
}
REPRODUCIBILITY :
This bug can be reproduced always.
(Incident Review ID: 186297)
======================================================================