Funnythat Funnythat - 1 month ago 9
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

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);