I'm afraid there is something suspicious about modifier handling for CTRL. That is: when checking the received modifier key = InputEvent.CTRL_MASK, advanced modifier = InputEvent.CTRL_DOWN_MASK. And the javadoc API is a little suspicious.
In addition, Ä is not a special case when “control” is not taken into account.
To make it work, I had to add a dirty hack: register a key listener that calls this action. I have to control something.
Otherwise, I used InputMap / ActionMap, as expected. The input map does not seem to work, but as far as I know, it does not work if it is added to the JTextField or in another answer (for Ä ). The following works are terrible.
final JLabel label = new JLabel("Text shall change with shortcut"); final KeyStroke key = KeyStroke.getKeyStroke((Character)'k', InputEvent.CTRL_DOWN_MASK, false); final Object actionKey = "auml"; final Action action = new AbstractAction() { @Override public void actionPerformed(ActionEvent event) { System.out.println("aha"); label.setText("It is working!!!"); } }; label.addKeyListener(new KeyAdapter() { @Override public void keyPressed(java.awt.event.KeyEvent e) { if (e.isControlDown() && e.getKeyChar() == 'ä') { System.out.println("Ctrl-ä"); label.getActionMap().get(actionKey).actionPerformed(null);
source share