Reputation: 5694
I want to detect every MouseEvent
in my JavaFx Scene
, especially mouse clicks. My following solution works for some clicks, but only on some controls not for every control. So my question is, is there a way to detect every MouseReleased
event on all Nodes
of a Scene
?
scene.addEventHandler(MouseEvent.ANY, (EventHandler<MouseEvent>) event -> {
EventTarget comp = event.getTarget();
logger.debug("## " + (comp != null ? comp.getClass().getSimpleName() : event.getClass().getSimpleName()) + " [" + event.getEventType() + "] ## Komponente: " + event.getTarget() + " --------> Details:" + event);
});
Upvotes: 0
Views: 1087
Reputation: 5694
Following @James_D suggestion, my logging is now working. To catch all events, its necessary to use an EventFilter
because an EventHandler
is missing Event
that are already consumed. The doc explains the differences:
addEventFilter
Registers an event filter to this scene. The filter is called when the scene receives an Event of the specified type during the capturing phase of event delivery.addEventHandler
Registers an event handler to this scene. The handler is called when the scene receives an Event of the specified type during the bubbling phase of event delivery.
A working code example:
scene.addEventFilter(MouseEvent.MOUSE_RELEASED, (EventHandler<MouseEvent>) event -> {
EventTarget comp = event.getTarget();
logger.debug("## " + (comp != null ? comp.getClass().getSimpleName() : event.getClass().getSimpleName()) + " [" + event.getEventType() + "] ## Komponente: " + event.getTarget() + " --------> Details:" + event);
});
Upvotes: 1