Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFx, event interception/consumption

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.

like image 828
QuidNovi Avatar asked Jul 22 '26 18:07

QuidNovi


1 Answers

  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;
        }
    });
    
like image 90
Sergey Grinev Avatar answered Jul 28 '26 16:07

Sergey Grinev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!