JavaFx,事件拦截/消费 [英] JavaFx, event interception/consumption
本文介绍了JavaFx,事件拦截/消费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个部分场景图树:
I've got this partial scenegraph tree :
CustomPane (with onMouseClicked Handler)
→ ChildNode (with onMousePressed Handler)
当我在ChildNode中捕获MousePressed事件时,我可以使用它,以便parent未收到MousePressed事件。
但我想使用相关的MouseClicked事件。因此,在Child上按鼠标不会在Parent上触发MouseClicked事件。
When I catch the MousePressed event in the ChildNode, I can consume it, so that the parent doesn't receive a MousePressed event. But I would like to consume the associated MouseClicked event. So that pressing the mouse on the Child doesn't fire a MouseClicked event on the Parent.
推荐答案
-
您可以添加特定的
ChildNode#onMouse ...
处理程序,它将消耗所有事件。
You can add specific
ChildNode#onMouse...
handlers which will consume all events.
或提供你自己的 EventDispatcher
:
child.setEventDispatcher(new EventDispatcher() {
@Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {
boolean valid = myValidationLogicForEvents(event);
return valid ? tail.dispatchEvent(event) : null;
}
});
这篇关于JavaFx,事件拦截/消费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文