JavaFx, event interception/consumption

混江龙づ霸主 提交于 2019-12-31 02:10:08

问题


I've got this partial scenegraph tree :

CustomPane (with onMouseClicked Handler)
 → ChildNode (with onMousePressed Handler)

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.


回答1:


  1. You can add specific ChildNode#onMouse... handlers which will consume all events.

  2. or provide your own EventDispatcher:

    child.setEventDispatcher(new EventDispatcher() {
    
        @Override
        public Event dispatchEvent(Event event, EventDispatchChain tail) {
            boolean valid = myValidationLogicForEvents(event);
            return valid ? tail.dispatchEvent(event) : null;
        }
    });
    


来源:https://stackoverflow.com/questions/19498867/javafx-event-interception-consumption

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!