N
N
Nikita Kolosov2012-06-06 08:44:58
Java
Nikita Kolosov, 2012-06-06 08:44:58

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 == trueelements JMenuBarare available, they work. But the window does not react to any key presses.

isFocusedand isActivealsotrue

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BrightGenie, 2012-06-06
@Anexroid

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

B
barker, 2012-06-06
@barker

Indeed, what exactly did you hang the KeyListener on and where exactly do you press the buttons?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question