JDK-4350717 : Keyboard actions do not work if mouse button is pressed
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 2000-07-05
  • Updated: 2001-01-11
  • Resolved: 2001-01-11
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
EVALUATION This is happening because under Solaris the modifiers are 16 (button1) where as on windows the modifiers are 0. I am reassigning to AWT as both platforms should ideally behave the same. I am also going to up the priority as this makes it hard for developers to go between the two platforms. This also might bite swing with drag and drop support when the user hits escape when dragging. scott.violet@eng 2000-07-11 Name: ssR10077 Date: 01/11/2001 Fixed by RFE 4387938 ======================================================================
11-07-2000

WORK AROUND Register the binding with the BUTTON_1 modifier. scott.violet@eng 2000-07-11
11-07-2000