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

JSpinner keeps spinning while JOptionPane is shown on ChangeListener

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.4.1, 1.4.2
    • client-libs
    • tiger
    • x86
    • windows_2000, windows_xp



      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)
      ======================================================================

            apikalev Andrey Pikalev
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: