Question Details

No question body available.

Tags

javafx scroll mouseevent

Answers (1)

October 30, 2025 Score: 2 Rep: 579 Quality: Low Completeness: 60%

I found some workaround code.

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.Node;
import javafx.scene.input.ScrollEvent;
import javafx.util.Duration;

public class ScrollFinishedDetector {

private final Timeline scrollFinishedTimeline; private long lastScrollTime = 0;

public ScrollFinishedDetector(Node node, Duration delay) { // Initialize the Timeline scrollFinishedTimeline = new Timeline(new KeyFrame(delay, event -> { // This code executes if no scroll event occurs for the specified 'delay' if (System.currentTimeMillis() - lastScrollTime >= delay.toMillis()) { System.out.println("Mouse wheel scrolling finished!"); // Perform actions when mouse wheel scrolling is deemed finished } })); scrollFinishedTimeline.setCycleCount(Timeline.INDEFINITE);

// Add a handler for ScrollEvents node.addEventHandler(ScrollEvent.SCROLL, event -> { if (!event.isInertia()) { // Ignore inertia events if desired lastScrollTime = System.currentTimeMillis(); // Ensure the timeline is playing to detect inactivity if (scrollFinishedTimeline.getStatus() != Timeline.Status.RUNNING) { scrollFinishedTimeline.play(); } } });

// Add a handler to stop the timeline when scrolling truly stops // This is a more robust way to ensure the timeline restarts correctly node.addEventHandler(ScrollEvent.SCROLL_FINISHED, event -> { // This will only fire for touch gestures, not mouse wheel scrollFinishedTimeline.stop(); }); }

public void startDetection() { scrollFinishedTimeline.play(); }

public void stopDetection() { scrollFinishedTimeline.stop(); } }

Using the class

ScrollFinishedDetector detector = new ScrollFinishedDetector(scrollPane, Duration.millis(60));
detector.startDetection();