JavaFX's ScrollPane panes on all mouse events when allowed to pan:
scrollPane.setPannable(true);
How to limit the ScrollPane to pan only on middle mouse events, while still allowing all events to get to the StackPane's content?
You should consume all events except the middle button events inside the content's event handler:
// Let the ScrollPane.viewRect only pan on middle button.
imageLayer.addEventHandler(MouseEvent.ANY, event -> {
if(event.getButton() != MouseButton.MIDDLE) event.consume();
});
This works because the ScrollPane pans via an event handler too, and event handlers are invoked bottom-up. Thus if we consume the event via the child, it won't get to the ScrollPane viewRect which does the panning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With