Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javafx Disable Scrolling by Mousewheel in ScrollPane

Does anayone know how to disable scrolling by Mousewheel in a ScrollPane?

like image 462
Studiosus Avatar asked Dec 05 '25 08:12

Studiosus


1 Answers

The following works for me:

    scrollPane.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() {
        @Override
        public void handle(ScrollEvent event) {
            if (event.getDeltaY() > 0) {
                zoomIn();
            } else {
                zoomOut();
            }
            event.consume();
        }});

You may find that you also need something like the following:

scrollPane.setOnScroll(new EventHandler<ScrollEvent>() {
    @Override
    public void handle(ScrollEvent event) {
        if (event.getDeltaY() > 0) {
            zoomIn();
        } else {
            zoomOut();
        }
        event.consume();
    }
});

I added the above elaboration to another answer in this thread, but it hasn't shown up in the public feed from what I can tell. So, I've pasted it in its own answer.

This question is a bit of a duplicate, but it showed up in Google for me first, so I'm answering it. The inspiration for the above is:

Zooming in JavaFx: ScrollEvent is consumed when content size exceeds ScrollPane viewport

like image 101
interestedparty333 Avatar answered Dec 08 '25 12:12

interestedparty333



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!