Last active
August 14, 2018 10:45
-
-
Save davidvarga/aac1f9ac3d98aa87daf6bbbe701ef12f to your computer and use it in GitHub Desktop.
ScrollablePane StackOverflow (
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.application.Platform; | |
import javafx.beans.property.ObjectProperty; | |
import javafx.beans.property.SimpleObjectProperty; | |
import javafx.event.EventHandler; | |
import javafx.scene.Scene; | |
import javafx.scene.input.ScrollEvent; | |
import javafx.scene.layout.BorderPane; | |
import javafx.scene.layout.Pane; | |
import javafx.stage.Stage; | |
public class MyApplication extends Application { | |
@Override | |
public void start(Stage primaryStage) { | |
try { | |
BorderPane root = new BorderPane(); | |
Scene scene = new Scene(root, 400, 400); | |
ScrollablePane pane = new ScrollablePane(); | |
pane.setOnScrollEnded(e -> System.out.println("Scroll just has been ended")); | |
root.setCenter(pane); | |
primaryStage.setScene(scene); | |
primaryStage.show(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
launch(args); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.beans.property.ObjectProperty; | |
import javafx.beans.property.SimpleObjectProperty; | |
import javafx.event.EventHandler; | |
import javafx.scene.input.ScrollEvent; | |
import javafx.scene.layout.Pane; | |
public class ScrollablePane extends Pane { | |
private Integer scrollCounter = 0; | |
private final ObjectProperty<EventHandler<? super ScrollEvent>> onScrollEnded = new SimpleObjectProperty<>(); | |
public final ObjectProperty<EventHandler<? super ScrollEvent>> onScrollEndedProperty() { | |
return onScrollEnded; | |
} | |
public ScrollablePane() { | |
this.setOnScroll(e -> { | |
scrollCounter++; | |
Thread th = new Thread(() -> { | |
try { | |
Thread.sleep(1000); | |
if (scrollCounter == 1) | |
onScrollEnded.get().handle(e); | |
scrollCounter--; | |
} catch (Exception e1) { | |
e1.printStackTrace(); | |
} | |
}); | |
th.setDaemon(true); | |
th.start(); | |
}); | |
} | |
public void setOnScrollEnded(EventHandler<? super ScrollEvent> handler) { | |
onScrollEnded.setValue(handler); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer of question: https://stackoverflow.com/questions/40843062/javafx-scroll-started-and-ended/40843471#40843471