How do you make key binding for a JFrame no matter what JComponent is in focus?

前端 未结 3 1017
面向向阳花
面向向阳花 2020-12-19 05:28

How do we make key bindings for a JFrame regardless of what\'s in focus in the frame?

I already looked at this question: How do you make key bindings for a java.awt.

3条回答
  •  时光说笑
    2020-12-19 05:59

    You could try using JComponent#getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)

    From the Java Docs

    Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is in the window that has the focus or is itself the focused component.

提交回复
热议问题