JPanel is not configured by default. That is, he cannot respond to events related to the focus, which means that he cannot respond to key events.
I would suggest trying to set Focus on the panel to true and try again. Make sure you press the panel first to make sure it gets focus.
Understand, however, you will get strange problems with focus traversal, since the panel will now receive input focus when the user moves through your forms, and it seems that the focus has been lost somewhere.
In addition, KeyListener
tends to be unreliable in a similar situation (due to the focus manager working).
source share