JDK-4840869 : JSpinner keeps spinning while JOptionPane is shown on ChangeListener
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1,1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2003-04-01
  • 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
Duplicate :  
Relates :  
Description

Name: jk109818			Date: 04/01/2003


FULL PRODUCT VERSION :
since 1.4.0, still in 1.4.1_02

FULL OS VERSION :
Windows NT 4.0, Windows XP

A DESCRIPTION OF THE PROBLEM :
I created a JSpinner with a SpinnerNumberModel and a ChangeListener that
listens for value-changes of the Spinner. The Listener validates the
value and displays a JOptionPane if a special value is reached. While
the JOptionPane is visible the Spinner keeps spinning the values until
either the JOptionPane is closed or the max/min value is reached.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Start the application given in the Source-Code Section and increase the
Spinner's value. When the spinner reaches the value "21" a JOptionPane will be
displayed and the Spinner runs to value 50 which is the maximum value.


EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect the Spinner's value to stay at the value that was
visible before the JOptionPane opended. ("21" in the example).
When the spinner reaches the value "21" a JOptionPane will be displayed
and the Spinner runs to value 50 which is the maximum value.


REPRODUCIBILITY :
This bug can be reproduced always.

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

public class SpinnerFrame extends JFrame implements ChangeListener {

    private JSpinner spinner;

    private boolean changing;

    private SpinnerFrame() {
        super();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().add(getSpinner());
        setSize(80,60);
        setLocation(200, 300);
        setVisible(true);
        changing = false;
    }
    
    private JSpinner getSpinner() {
        if (spinner == null) {
            spinner = new JSpinner();
            spinner.setModel(new SpinnerNumberModel(10, 1, 50, 1));
            spinner.addChangeListener(this);
        }
        return spinner;
    }

    public void stateChanged(ChangeEvent e) {
        JSpinner spinner = (JSpinner) e.getSource();
        int value = ((Integer) spinner.getValue()).intValue();
        System.out.println("Changed to " + value);
        if (changing) {
            return;
        }
        changing = true;
        if (value > 20) {
            JOptionPane.showMessageDialog(this, "20 exceeded");
        }
        changing = false;
    }

    public static void main(String[] args) {
        new SpinnerFrame();
    }
}

---------- END SOURCE ----------
(Review ID: 183126) 
======================================================================

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

EVALUATION Name: apR10133 Date: 04/02/2003 The cause of this bug is that we get ChangeEvent and transfer the focus to the message dialog before the mouse is released. Hence we don't stop the autorepeat timer and continue to increase the spinner value. We have to stop this timer when spinner lost the focus. ###@###.### ======================================================================
24-08-2004