I must be missing something here, but I can't figure out why the InputEvent.CTRL_DOWN_MASK
nor InputEvent.CTRL_MASK
work?
What I am trying to do is implement a way for Ctrl-C to issue a command in a Swing GUI. I am using the following code:
myTextArea.getInputMap(JComponent.WHEN_FOCUSED).put(
KeyStroke.getKeyStroke((char) 'c', /***/InputEvent.CTRL_DOWN_MASK/***/), "ctrl");
myTextArea.getActionMap().put("ctrl", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("test");
}
});
Notice the InputEvent.CTRL_DOWN_MASK
. When I keep it in there, the action never gets performed. When I comment it out, the action works (but I am only pressing the lower-case 'c' button. Not ctrl.
Am I missing something on how to really use the CTRL_MASK for swing key events?