JavaFX相当于java.awt.EventQueue [英] JavaFX equivalent to java.awt.EventQueue

查看:142
本文介绍了JavaFX相当于java.awt.EventQueue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaFX是否包含与java.awt.EventQueue等效的内容?对于我的应用程序,我需要拦截所有与GUI相关的事件,例如鼠标和键盘输入,到目前为止,我还没有找到一种方法来实现它而不将侦听器连接到每个GUI元素。

Does JavaFX contain an equivalent to java.awt.EventQueue? For my application I need to intercept all GUI related events such as mouse and keyboard input, and so far I haven't been able to find a way to do it without attaching listeners to every GUI element.

推荐答案

这与标题中的问题不完全相同,但是为了拦截所有事件,您可以向场景中添加一个EventFilter:

This isn't quite the same as the question in your title, but to intercept all events, you can add an EventFilter to the Scene:

scene.addEventFilter(Event.ANY, new EventHandler<Event>() {
        @Override
        public void handle(Event event) {
            System.out.println(event);
        }
});

如果您需要否决该事件,请致电 event.consume()

If you need to veto the event, call event.consume()

这篇关于JavaFX相当于java.awt.EventQueue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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