Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6463712
Votes 0
Synopsis JSpinner forwards ChangeEvents from old model
Category java:classes_swing
Reported Against
Release Fixed 7(b20)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs
Submit Date 24-AUG-2006
Description
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 ----------
Posted Date : 2006-08-24 20:45:10.0
Work Around
N/A
Evaluation
Yep, this is a bug in JSpinner.setModel. It's adding a listener to the new model, but not removing the listener from the old model.
Posted Date : 2006-08-28 18:27:24.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang