n247s
n247s

Reputation: 1918

JavaFX8 Disable Scrolling of ScrollPane

I was wondering if there is a way to disable/prevent scrolling in a ScrollPane?

Basically I have a Canvas wrapped in a Group object to enable zooming (which is done by 'Ctrl + scroll'). Though for some reason the ScrollPane consumes the event (if it can be scrolled) before it fires any other scrollEvent (e.g. the ScrollEvent from the Canvas, Group, ScrollPane and even the ScrollPane's Parent!).

So I was wondering what the options are (if there are any) to catch a scrollEvent before it is consumed by the ScrollPane.

Thanks for your time

Upvotes: 1

Views: 1423

Answers (1)

n247s
n247s

Reputation: 1918

Thanks to joshpy I got the answer.

I forgat that EventFilters are a thing in javafx. Luckly you can consume the Event in the eventFilter as well, so here is the solution.

scrollPane.addEventFilter(ScrollEvent.SCROLL, event -> {
   if(event.isControlDown())
   {
      zoomCanvas(event) // zoom the canvas instead of scrolling the actual pane.
      event.consume();
   }
});

Many thanks for the tip! Although Im still not sure why an usual event wouldn't work.

Upvotes: 2

Related Questions