I am having trouble reproducing the problem you described. I usually modify the component InputMap, but the instance UIManagerhas default bindings. In the example below
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), NIL);
effectively blocks the key Spacefrom calling the button ActionListener. Uncommenting line
button.getActionMap().put(NIL, nil);
Space , doNothing, .
public class NilBindingTest extends JPanel {
private static final String NIL = "none";
private Action nil = new AbstractAction(NIL) {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("\"" + e.getActionCommand() + "\"");
}
};
private JButton button = new JButton(nil);
private InputMap im = (InputMap) UIManager.get("Button.focusInputMap");
public NilBindingTest() {
this.add(new JButton("foo"));
System.out.println(Arrays.toString(im.keys()));
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), NIL);
this.add(button);
}
private void display() {
JFrame f = new JFrame("NilBindingTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new NilBindingTest().display();
}
});
}
}