Funnythat Funnythat - 1 year ago 122
Java Question

JavaFX MousedMoved event ignored when mouse button is held down

The event within

main.getScene().addEventFilter(MouseEvent.MOUSE_MOVED, new EventHandler<MouseEvent>() {}

is not called when the mouse button is held down, is there anyway around this? Thanks.

Answer Source

A mouse moved with the mouse button down is a MOUSE_DRAGGED event. So you can do:

EventHandler<MouseEvent> handler = event -> { /* ... */};
main.getScene().addEventFilter(MouseEvent.MOUSE_MOVED, handler);
main.getScene().addEventFilter(MouseEvent.MOUSE_DRAGGED, handler);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download