In Swing, how to apply KeyListener on no specific component

前端 未结 2 900
孤城傲影
孤城傲影 2020-12-18 10:46

Generally we apply the Key Listener on specific components like text field, password fields, etc. But I would like to generalize this listener behavior to be applicable to a

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-18 11:19

    Swing was designed to be used with Key Bindings which might do what you want. I would start by checking out Key Bindings. Don't forget to read the Swing tutorial for complete information.

    If that doesn't help then see Global Event Listeners for a couple of suggestions.

提交回复
热议问题