'How to handle the mouse wheel scrolling event using JavaFX?

Just need to get some numeric equivalent, which will show how much the wheel is scrolled.

I managed to find an example only using awt/swing: Java Docs

P.S. Sorry for my English.



Solution 1:[1]

{
...
    sceneChart.setOnScroll(event -> print(event));
}

public void print (ScrollEvent event) {
    System.out.println(event.getDeltaY());
}

Solution 2:[2]

add onScroll to your javafx element to handle scroll event
for example here add onScroll to ImageView

<ImageView onScroll="#onScrollImageView" .........../>

and handle that in fxml controller like here:

public void onScrollImageView(ScrollEvent scrollEvent) {
            double deltaY = scrollEvent.getDeltaY();

            if(deltaY<0)
               //scroll up
            if(deltaY>0)
               //scroll down
    }

getDeltaY() return the vertical scroll amount.
and negative value of getDeltaY() or positive value means scroll direction

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 it-efrem
Solution 2