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

On TAB, JSpinner first turns focus, then calls ChangeListener

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs
    • x86
    • windows_xp

      Name: jk109818 Date: 05/17/2002


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

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      ADDITIONAL OPERATING SYSTEMS :
      Microsoft Windows 2000

      A DESCRIPTION OF THE PROBLEM :
      If you edit(!) a JSpinner and press TAB afterwards, first
      the focus turns and after that, any ChangeListeners on the
      JSpinner are called.

      This leads to the following problem: If you put a
      ChangeListener on a JSpinner for controlling values of the
      JSpinner, and want to disable the next (or last) Component
      in some cases for some values of the JSpinner, the next
      (or last) Component will be disables AND get Focus (that's
      the bug). Now the Focus is "catched" on the disabled
      Component :-(((

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the given code.
      2. Edit (!, do not spin) the value to 5.
      3. Press TAB

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected Result: JButton gets disabled and Focus stays on
      JSpinner.

      Actual Result: JButton gets disabled (ok) AND gets Focus.

      This bug can be reproduced always.

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

      public class SpinnerBug extends JFrame {
        private JButton jButton = new JButton();
        private JSpinner jSpinner = new JSpinner();

        public SpinnerBug() {
          getContentPane().setLayout(new FlowLayout());
          jButton.setText("jButton");
          jSpinner.setModel(new SpinnerNumberModel(1,1,10,1));
          jSpinner.getModel().addChangeListener(new ChangeListener(){
            public void stateChanged(ChangeEvent e){
              if (((Integer)jSpinner.getValue()).intValue() == 5){
                jButton.setEnabled(false);
              } else {
                jButton.setEnabled(true);
              }
            }
          });
          getContentPane().add(jButton);
          getContentPane().add(jSpinner);
          pack();
          setVisible(true);
        }

        public static void main(String[] args) {
          SpinnerBug spinnerBug = new SpinnerBug();
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Try to listen to the TextField of the Editor and disable
      Component "on the fly".
      (Review ID: 146728)
      ======================================================================

            ant Anton Tarasov (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: