If you search this problem, you’ll see that it is asked and has been solved many times.
- KeyListeners need to be on the focused component to work. One solution is to give your component the focus after first making it focusable.
- Better by a long shot however is to use Key Bindings. Google the tutorial on this.
Please have a look at my answer to this question for more on this, including many of the gory details.