JDK-4765259 : JTabbedPane.insertTab doesn't care about selected index
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P5
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2002-10-18
  • Updated: 2003-04-25
  • Resolved: 2003-04-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Relates :  
Description

Name: sv35042			Date: 10/18/2002


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)


i experienced the same behaviour also under:

java version "1.3.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_02-b02)
Java HotSpot(TM) Client VM (build 1.3.1_02-b02, mixed mode)


FULL OPERATING SYSTEM VERSION :
Windows NT Version 4.0

A DESCRIPTION OF THE PROBLEM :
I have a JTabbedPane with one Tab that is (of course)
selected. (getSelectedIndex returns 0) Then I fill in a new
Tab before that first one using insertTab. Now this new one
is selected (getSelectedIndex still returns 0) but I did not
get a ChangeEvent that a different Tab got selected.

What I was expecting was that the old selected Tab would
remain selected and the result of getSelectedIndex would be
updated without firing ChangeEvents.

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package at.co.systema.ui.controls.guitests;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class TabbedPaneInsertBug
{
    public static void main(String P_params[])
    {
        JFrame frame = new JFrame();
        frame.addWindowListener (new WindowAdapter()
        {
            public void windowClosing(WindowEvent e) { System.exit(0); }
        });

        final JTabbedPane tp = new JTabbedPane();
        tp.setPreferredSize(new Dimension(200, 150));
        tp.addChangeListener(new ChangeListener()
        {
            public void stateChanged(ChangeEvent e)
            {
                System.out.println("ChangeEvent ... " + tp.getSelectedIndex() +
" \"" + tp.getTitleAt(tp.getSelectedIndex()) + "\"");
            }
        });
        frame.getContentPane().add(tp);

        tp.addTab("Tab 3", new JButton("3"));
        tp.insertTab("Tab 1", null, new JButton("1"), null, 0);
        tp.insertTab("Tab 2", null, new JButton("2"), null, 1);
        tp.addTab("Tab 4", new JButton("4"));

        System.out.println("currently selected index: " + tp.getSelectedIndex()
+ " \"" + tp.getTitleAt(tp.getSelectedIndex()) + "\"");

        frame.pack();
        frame.setVisible(true);
    }
}

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Do a setSelectedIndex for the new index of the previously
selected tab again and find a way to ignore the ChangeEvent
in this special case.
(Review ID: 148138) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b06
14-06-2004

EVALUATION Name: omR10226 Date: 03/06/2003 JTabbedPane represents an integer selection and fires change notification only when that integer changes. After inserting of a new tab the selected index isn't changed so stateChanged-event isn't fired. ====================================================================== After the fix: If a new tab is inserted before the selected tab then the selected index is increased by one. Such behaviour is like Windows native tabbed pane behaviour. It allow to avoid situation when a selected tab is changed, but a selected index isn't changed and event stateChanged() isn't fired. ###@###.### 2003-04-04
04-04-2003