如何添加全局动作事件侦听器? [英] How to add global action event listener?

查看:129
本文介绍了如何添加全局动作事件侦听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加全局动作事件侦听器?我试过

How to add a global action event listener? I've tried

Toolkit.getDefaultToolkit ().addAWTEventListener (this, AWTEvent.ACTION_EVENT_MASK); 

但它不起作用。

推荐答案

全局听Action Action不适用于像JButtons这样的Swing组件,因为它们直接调用其监听器,而不是通过AWT事件队列调度事件。 Java bug 6292132 描述了这个问题。

Globally listening to Action Events does not work for Swing components like JButtons since they directly call their listeners instead of dispatching the event through the AWT event queue. Java bug 6292132 describes this problem.

不幸的是,我知道在每个组件注册侦听器之前没有任何解决方法。

Unfortunately, I know of no workaround short of registering the listener with every component.

这篇关于如何添加全局动作事件侦听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆