سؤال

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