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

Keyboard actions do not work if mouse button is pressed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.0
    • client-libs
    • sparc
    • solaris_7



      Name: sl110371 Date: 07/05/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-beta)
      Java HotSpot(TM) Client VM (build 1.3-beta, mixed mode)


      Actions that are bound to keyboard bindings via registerKeyboardAction or the
      new InputMap/ActionMap functionality will not work(ie they won't get called) if
      a mouse button is pressed. This works fine on NT using the 1.3fcs but on
      Solaris, and HP for that matter, there appears to be a bug. This is important
      because it is needed to support cancelling mouse based operations(like drawing)
      via the Escape key.

      The following test app will show the problem. Run it on NT and then on Solaris
      and you'll notice the action will not fire on Solaris if you hold down a mouse
      button.

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class keytest extends JFrame {

         public static void main(String[] args) {
            new keytest();
         }
         public keytest() {
            addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {
                  System.exit(0);
               }}
            );

            final JPanel p = new JPanel();
            p.setOpaque(true);
            p.setBackground(Color.yellow);

            InputMap im = p.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
            im.put(KeyStroke.getKeyStroke("ESCAPE"), "esc");
            p.getActionMap().put("esc", new AbstractAction() {
               public void actionPerformed(ActionEvent e) {
                  System.out.println("Action ESCAPE");
               }
            });

            getContentPane().add(p);
            pack();
            setBounds(300,300,300,300);
            setVisible(true);

            p.requestFocus();
            p.addKeyListener(new KeyAdapter() {
               public void keyPressed(KeyEvent e) {
                  if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                     System.out.println("KeyListener ESCAPE");
                  }
               }
            });
         }
      }
      (Review ID: 106886)
      ======================================================================

            ssisunw Ssi Ssi (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: