JDK-4905383 : removeTabAt method setSelectedIndex incorrectly
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux
  • CPU: x86
  • Submitted: 2003-08-12
  • Updated: 2003-08-14
  • Resolved: 2003-08-14
Related Reports
Relates :  
Description

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) 
======================================================================

Comments
EVALUATION Name: omR10226 Date: 08/14/2003 This is not a bug. In the described situation, when we are removing any tab and selected tab is last tab, we should change the selected index reducing it by one. We should do it independently from the index of removed tab. Because the total number of tab is reduced after removing and tab with previously selected index doesn't exist. ======================================================================
11-06-2004