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

Unable to stop ChangeEvents from JSpinner when ChangeEvents show a Modal dialog

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • client-libs



      Name: rmT116609 Date: 10/14/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

      java version "1.4.2_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
      Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      JSpinner updates its field using the buttons or keys. A
      single event occurs if the button or key is hit once but if
      the key or button is held down many events occur in rapid
      succession. I am trying to write an application that shows
      a modal dialog, stating that the spinner is not the correct
      item to be used next in a sequence of instructions. The
      dialog is modal. The JSpinner generates many events from
      holding the button (it may actually generate infinite
      events as it appears the button is "stuck" on the down
      postion. This is evidenced by the fact that if you remove
      the listener then hide the dialog, the spinner spins out of
      control.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Press and hold a JSpinner button
      2. On a ChangeEvent, show a modal dialog
      3. hide the dialog.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      1. If you don't remove the listener, the dialog appears
      over and over again.
      2. If you remove the listener the button is "stuck".

      I would like to be able to halt the changes so the spinner
      can complete one full cycle release its button and receive
      no more events.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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



      public class spinControl extends JFrame {

          private SpinnerNumberModel snm = new SpinnerNumberModel(new Integer
      (1),null,null,new Integer(1));
          private JSpinner jSpinner = new JSpinner(snm);
      private JDialog dialog = new JDialog();
          private JButton jButton = new JButton("OK");
      private JPanel jPanel = new JPanel();

          public spinControl() {

      dialog.setModal(true);
      dialog.getContentPane().add(jButton);

              jButton.addActionListener(new ActionListener(){
                  public void actionPerformed(ActionEvent e){
                      dialog.setVisible(false);
                  }
              });

              jSpinner.addChangeListener(new ChangeListener(){
                  public void stateChanged(ChangeEvent e){
      dialog.pack();
      //jSpinner.removeChangeListener
      (jSpinner.getChangeListeners()[0]); // this makes the button stick.
                      dialog.show();
                  }
              });


              jPanel.add(jSpinner);
              getContentPane().add(jPanel);
              pack();
              setVisible(true);
          }

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

      CUSTOMER WORKAROUND :
      I just won't be able to react to the user pressing the spinner when they are not supposed to. Ultimately it makes the application inconsistent.
      (Incident Review ID: 167251)
      ======================================================================

            apikalev Andrey Pikalev
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: