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

JSpinner(or it's editor) does not fire KeyEvent

    XMLWordPrintable

Details

    • generic, x86
    • generic, windows_2000, windows_xp

    Description

      Name: sv35042 Date: 10/08/2002


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

      FULL OPERATING SYSTEM VERSION : Windows 2000 5.00.2195 SP2


      ADDITIONAL OPERATING SYSTEMS : n/a



      A DESCRIPTION OF THE PROBLEM :
      The JSpinner class supports the addKeyListener method of
      Component, but the spinner never calls the keyPressed,
      keyReleased, or keyTyped methods of an object implementing
      the KeyListener interface. Also, using getEditor
      ().addKeyListener, to add a KeyListener to the JComponent
      that is the JSpinner editor works without error, however,
      it never calls any of the KeyListener methods either.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a JSpinner with a model.
      2. addKeyListener directly to the JSpinner object
      3. addKeyListener to the JSpinner editor retrieved by
      getEditor.
      4. Implement keyPressed, keyReleased, keyTyped, and verify
      that these methods are never invoked when a keyboard action
      occurs on the spinner.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Each of the KeyListener methods should have been invoked
      due to pressing a key while the JSpinner had focus. This
      never happened.

      This bug can be reproduced always.

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

      public class Test extends JFrame implements KeyListener {

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

        public Test() {
          SpinnerNumberModel model = new SpinnerNumberModel();
          model.setMinimum(new Integer(1));
          model.setMaximum(new Integer(10));

          JSpinner spinner = new JSpinner(model);
          spinner.addKeyListener(this);
          spinner.getEditor().addKeyListener(this);

          getContentPane().add(spinner);
          setSize(100, 100);
          show();
        }

        public void keyPressed(KeyEvent ke) {
          System.out.println("key " + ke.getKeyCode() + " pressed on " + ke.getSource
      ());
        }

        public void keyReleased(KeyEvent ke) {
          System.out.println("key " + ke.getKeyCode() + " released on " + ke.getSource
      ());
        }

        public void keyTyped(KeyEvent ke) {
          System.out.println("key " + ke.getKeyCode() + " typed on " + ke.getSource
      ());
        }

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

      Attachments

        Issue Links

          Activity

            People

              svioletsunw Scott Violet (Inactive)
              svioletsunw Scott Violet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: