Freewind
Freewind

Reputation: 198398

`TextArea.setOnScroll` doesn't be invoked when I scroll mouse wheel?

I have a TextArea, and have been set a handler for the scroll event:

myTextarea.setOnScroll((event) -> {
     System.out.println("setOnScroll: " + event);
});

But I found when the text in the textarea are very long, and if I put my mouse on it and scroll the mouse wheel, it doesn't print the event!

Only if the text reaches to the end, it starts to show the event.

I also tried setOnScrollStarted, and setOnScrollFinished, the same situation happens.

How to capture each scroll event in JavaFX?

Upvotes: 0

Views: 716

Answers (1)

Freewind
Freewind

Reputation: 198398

Finally I found the solution:

myTextarea.addEventFilter(ScrollEvent.ANY, (x) -> {
    System.out.println("scrolled");
});

Seems a little strange to use the method addEventFilter, but it works.

Upvotes: 3

Related Questions