Listening to key events for a component hierarchy

前端 未结 4 846
抹茶落季
抹茶落季 2021-01-18 12:11

I have a Swing app that needs to display different sets of controls based on whether the control or alt keys are pressed. I added a KeyListener to the main component, but i

4条回答
  •  孤街浪徒
    2021-01-18 12:58

    You may want to try to use key binding rather than KeyListeners. Key binding is a higher level construct and can listen for key presses even if the component that "listens" doesn't have the focus -- as opposed to KeyListeners. You can find more on these at the Swing tutorials: How to use key bindings

提交回复
热议问题