I need that all the key events (including Carriage Return, TAB, etc) generated by all child or grandchildren components of a JFrame, to be listened for a single method inside this JFrame. I have googled a lot, but I have not been able to find the solution I need. I found a partial solution using "InputMap/ActionMap", but it only allows to add particular KeyStrokes on the InputMap, but I need all possible Key Strokes to be forwarded to the parent JFrame.

Thanks.

(I saw this thread, but I was expecting a solution within the Swing API, specifically to address this subject.

有帮助吗?

解决方案

Check out Global Event Listeners which gives you a couple of choices:

  1. Use an AWTEventListener.
  2. Us a KeyEventPostProcessor.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top