将所有关键事件转发到父JFrame

时间:2014-05-12 16:07:41

标签: java swing events key-events

我需要听取JFrame的所有子孙组件生成的所有关键事件(包括Carriage Return,TAB等),以便在此JFrame中监听单个方法。我google了很多,但我找不到我需要的解决方案。我找到了使用“InputMap / ActionMap”的部分解决方案,但它只允许在InputMap上添加特定的KeyStrokes,但我需要将所有可能的Key Strokes转发到父JFrame。

感谢。

(我看到this线程,但我期待Swing API中的解决方案,专门用于解决这个问题。

1 个答案:

答案 0 :(得分:1)

查看Global Event Listeners,它会为您提供以下几种选择:

  1. 使用AWTEventListener
  2. 我们KeyEventPostProcessor