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

BACKSPACE key is not consumable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.4.2
    • client-libs
    • x86
    • solaris_2.5.1

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


      ADDITIONAL OS VERSION INFORMATION :
      SunOS ----- 5.9 Generic_118558-02 sun4u sparc SUNW,Sun-Fire-V250

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      May use Exceed or Citrix as a X Server

      A DESCRIPTION OF THE PROBLEM :
      The consume() method of the KeyEvent class is invoked whenever the application intercepts a backspace key event. The consume operation within the AWT is apparently not implemented and the backspace keystroke propagates through a DefaultEditor, for example, producing effects in the edited document.

      The Std. Ed. v1.4.2 documentation for the AWTEvent consume() method states "Consumes this event, if this event can be consumed. Only low-level, system events can be consumed "

      The backspace key press event seems to be a low-level event fully comparable to a delete key event, for instance. Both the keyPressed() and keyReleased() methods of KeyEventListener are called by AWT allowing an application to intercept such an event. Therefore, one would logically expect the consume() operation to be effective. If the backspace key cannot be consumed for some other reason, please state so in the JDK documentation.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Press the backspace key in an application which intercepts key events.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      consume() should short-circuit the backspace key event and not allow it to be further propagated.
      ACTUAL -
      The backspace key event is further propagated through the AWT and application layers.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      source code:

            KeyAdapter keyListener = new KeyAdapter()
            {
               public void keyPressed(KeyEvent event)
               {
                  if (event.getKeyCode() == KeyEvent.VK_BACK_SPACE)
                  {
                     System.out.println("BACKSPACE pressed");
                     event.consume();
                  }
               }

               public void keyTyped(KeyEvent event)
               {
                  if (event.getKeyCode() == KeyEvent.VK_BACK_SPACE)
                  {
                     System.out.println("BACKSPACE typed");
                     event.consume();
                  }
               }

               public void keyReleased(KeyEvent event)
               {
                  if (event.getKeyCode() == KeyEvent.VK_BACK_SPACE)
                  {
                     System.out.println("BACKSPACE released");
                     event.consume();
                  }
               }
            };

            editor = new JEditorPane();
            editor.addKeyListener(keyListener);

      console output for backspace, shift-backspace, ctrl-backspace & alt-backspace respectively:

      BACKSPACE pressed
      BACKSPACE released
      BACKSPACE pressed
      BACKSPACE released
      BACKSPACE pressed
      BACKSPACE released
      BACKSPACE pressed
      BACKSPACE released

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

      CUSTOMER SUBMITTED WORKAROUND :
      Application specific - in the reporter's case edited text within the document must be programmatically re-inserted.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: