Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6443600

REGRESSION: JTabbedPane listeners not notified before new tab becomes visible

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0-rc"
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b89)
      Java HotSpot(TM) Client VM (build 1.6.0-rc-b89, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When having a changeListener listening to a JTabbedPane that displays a dialog when a stateChanged event is received, past versions of the JRE (5.0 and earlier) would display the dialog over the current tab. In Mustang, the new tab is displayed before the dialog, which is a very undesireable behavior.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Add a changeListener to a JTabbedPane. In the stateChanged method that handles the tab switch, display a JOptionPane dialog.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The JOptionPane dialog should be displayed before the new tab is displayed. If a user chooses to cancel the tab switch from the dialog, they should be able to do so without seeing the new tab.
      ACTUAL -
      The JOptionPane dialog is displayed after the new tab is displayed.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.event.*;

      public class JTabbedPaneTest implements ChangeListener, Runnable{

      /*
      This test case was given to me by someone on a forum after I reported the problem.
      Passing in a parameter reverses the order of the listeners. So if I run it with a 0, I get the behavior where the tab is switched to first and then the Dialog appears.
      */

      int index;
      JTabbedPane jtp;
      static boolean swap;
      boolean cancel;
      public void run(){
      jtp = new JTabbedPane();
      if(swap){
      ChangeListener[] cl = jtp.getChangeListeners();
      for(ChangeListener cls: cl){
      System.out.println(cls);
      jtp.removeChangeListener(cls);
      }
      jtp.addChangeListener(this);
      for(ChangeListener cls: cl){
      jtp.addChangeListener(cls);
      }
      }
      else jtp.addChangeListener(this);
      for(int i = 0; i < 10; i ++){
      JPanel jp = new JPanel();
      jp.add(new JLabel(String.valueOf(i)));
      jtp.add(String.valueOf(i), jp);
      }
      JFrame jf = new JFrame();
      jf.add(jtp);
      jf.setSize(300,300);
      jf.setVisible(true);
      }

      public static void main(String ... args){
      if(args.length > 0) swap = true;
      SwingUtilities.invokeLater(new JTabbedPaneTest());
      }


      public void stateChanged(ChangeEvent e){
      if(jtp.getSelectedIndex() != index){
      final JDialog jd = new JDialog();
      JPanel jp = new JPanel();
      JButton dismiss = new JButton("Close");
      jp.add(dismiss);
      dismiss.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
      jd.setVisible(false);
      }
      });
      JButton cancelb = new JButton("Cancel");
      cancelb.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
      cancel = true;
      jd.setVisible(false);
      }
      });
      jp.add(cancelb);
      jd.add(jp);
      jd.setModal(true);
      jd.setSize(200,200);
      jd.show();
      if(cancel){
      cancel = false;
      jtp.setSelectedIndex(index);
      }
      index = jtp.getSelectedIndex();
      }
      }

      }
      ---------- END SOURCE ----------

      Release Regression From : mustang
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

      Attachments

        Activity

          People

            shickeysunw Shannon Hickey (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: