Answer the question
In order to leave comments, you need to log in
What is the reason for KeyListener not responding to keypresses? Java Swing?
Strange bug, temporary. That is, he is, then he is not. Then everything works OK, then after a couple of restarts, the window stops responding to keystrokes.
At the same time, the isFocusable == true
elements JMenuBar
are available, they work. But the window does not react to any key presses.
isFocused
and isActive
alsotrue
Answer the question
In order to leave comments, you need to log in
you can hang the processing of individual combinations on the window and all its descendants:
getRootPane().registerKeyboardAction(actionListener, "cancel", KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_IN_FOCUSED_WINDOW);
True, the Documentation says that the method is deprecated and instead you need to use a combination:
component.getInputMap().put(aKeyStroke, aCommand);
component.getActionMap().put(aCommand, anAction);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question