In a program I'm writing, I use a KeyListener to perform certain actions. However, I tried adding a KeyListener to the entire top level JFrame, and no events were received. When I had the JFrame request focus, the KeyEvents were received. However, I couldn't tell the JFrame to constantly request the focus, because then a user would not be able to minimize the JFrame or activate another window, as the JFrame would immediately pop up (due to the requesting of the focus).
So, what I tried next was adding the KeyListener to a JPanel, then having that JPanel constantly request focus. However, this caused another problem: other JComponents in the JFrame could not adequately perform their functions because the JPanel requesting focus would steal the focus from the JComponents prematurely...
So, for the meantime I have removed the KeyListener, but I am still irked about its performance (and my lack of knowledge). Is there any way to have a KeyListener receive KeyEvents without the host JComponent having the focus?
Any help or suggestions would be appreciate. Thanks!