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

JSpinner forwards ChangeEvents from old model

XMLWordPrintable

    • b20
    • x86
    • linux
    • Not verified

      FULL PRODUCT VERSION :
      java version "1.5.0_07"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_07-b03)
      Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_07-b03, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux ubuntu 2.6.12-10-amd64-xeon #1 SMP Fri Apr 28 13:33:06 UTC 2006 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      You can add a ChangeListener to a JSpinner and any changes to the spinner's model will result in a ChangeEvent being generated by the spinner as well. If you replace the spinner's model with a new one, the old model should not still be linked to the spinner in any way. But it is...try the test app below.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Please see the attached test program. Run with and without the indicated line in the code.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.JSpinner;
      import javax.swing.SpinnerDateModel;
      import javax.swing.SpinnerNumberModel;
      import javax.swing.event.ChangeEvent;
      import javax.swing.event.ChangeListener;

      public class JSpinnerBug implements ChangeListener {

        public JSpinnerBug()
        {
          SpinnerNumberModel m1 = new SpinnerNumberModel();
          JSpinner s = new JSpinner(m1);
          s.addChangeListener(this);
          SpinnerDateModel m2 = new SpinnerDateModel();
          s.setModel(m2);
          
          // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
          // the following should not trigger a call to our stateChanged() method...
          m1.setValue(new Integer(1));
          // try running with the above line commented out and compare the result.
        }
          
        public void stateChanged(ChangeEvent e)
        {
          System.out.println("stateChanged(" + e.getSource() + ")");
        }

        public static void main(String[] args)
        {
          JSpinnerBug bug = new JSpinnerBug();
        }
      }
      ---------- END SOURCE ----------

            rbair Richard Bair (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: