package de.fhg.iwes.javafx.test; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane.ScrollBarPolicy; import javafx.scene.effect.DropShadow; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.shape.StrokeType; import javafx.stage.Stage; import javafx.util.Duration; public class JavaFxScrollPanePerformance extends Application { public static void main(String[] args) { Application.launch(JavaFxScrollPanePerformance.class, args); } @Override public void start(final Stage primaryStage) throws Exception { // Set up stage primaryStage.setTitle("JavaFX 2.0 beta build 38"); final Group root = new Group(); final Scene scene = new Scene(root, 650, 600); primaryStage.setScene(scene); primaryStage.setVisible(true); final ScrollPane scrollPane = new ScrollPane(); scrollPane.setLayoutX(50); scrollPane.setLayoutY(50); scrollPane.setPrefSize(550, 450); scrollPane.setPannable(true); scrollPane.setVbarPolicy(ScrollBarPolicy.NEVER); root.getChildren().add(scrollPane); Group scrollPaneContent = new Group(); scrollPaneContent.setTranslateX(5); scrollPaneContent.setTranslateY(5); scrollPane.setContent(scrollPaneContent); Double yPosition = 0d; for (int i = 0; i < 2000; i++) { Rectangle rect = new Rectangle(510, 70, Color.WHITE); rect.setStroke(Color.BLACK); rect.setStrokeWidth(2); rect.setStrokeType(StrokeType.OUTSIDE); rect.setArcWidth(20); rect.setArcHeight(20); rect.setEffect(new DropShadow()); rect.setLayoutY(yPosition); scrollPaneContent.getChildren().add(rect); Label label = new Label("Item: " + i); label.setLayoutX(20); label.setLayoutY(yPosition + 10); scrollPaneContent.getChildren().add(label); yPosition += 86; } Button button1 = new Button("Scroll down"); button1.setLayoutX(50); button1.setLayoutY(530); button1.setOnAction(new EventHandler() { @Override public void handle(ActionEvent arg0) { Double oldVvalue = scrollPane.getVvalue(); Double newVvalue = oldVvalue + 0.0005; scrollPane.setVvalue(newVvalue); } }); root.getChildren().add(button1); Button button2 = new Button("Scroll down animated (NOT WORKING)"); button2.setLayoutX(250); button2.setLayoutY(530); button2.setOnAction(new EventHandler() { @Override public void handle(ActionEvent arg0) { Double oldVvalue = scrollPane.getVvalue(); Double newVvalue = oldVvalue + 0.0005; KeyValue keyValue = new KeyValue(scrollPane.vvalueProperty(), newVvalue); KeyFrame keyFrame = new KeyFrame(Duration.valueOf(500), keyValue); Timeline timeline = new Timeline(30, keyFrame); timeline.play(); } }); root.getChildren().add(button2); } }