简体   繁体   English

Java Swing中的全局加速器

[英]Global accelerator in java swing

I have made accelerators in my java gui by using setAccelerator(), and they work unless something with the same key binding is in focus. 我已经通过使用setAccelerator()在我的Java gui中创建了加速器,除非焦点相同的键绑定的东西才能使用加速器。 Is there a way to enable them globally so the action is triggered no matter what if the window has focus? 有没有一种方法可以全局启用它们,所以无论窗口是否具有焦点,都将触发操作?

jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK))

Take a look at Global Event Dispatching . 看一下全局事件调度 You should be able to use a KeyEventDispatcher to intercept any key event to do your custom processing. 您应该能够使用KeyEventDispatcher截获任何按键事件以进行自定义处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM