javafxports / openjdk-jfx

The openjfx repo has moved to:
https://github.com/openjdk/jfx
GNU General Public License v2.0
1.01k stars 145 forks source link

Scrolling speed in ScrollPane slow when content has similar size to container #417

Open Myrannas opened 5 years ago

Myrannas commented 5 years ago

Platform: OSX JavaFX Version: 12

Hi - I have noticed an interesting issue with the ScrollPane component. It looks like the scroll speed slows down when the content is almost the same size of the container. This is particularly apparent when the container is very large.

To reproduce create a scene similar to:

package app;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class HelloWorld extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        VBox container= new VBox();
        ScrollPane root= new ScrollPane(container);
        root.setContent(container);

        for (int i = 0; i < 50; i++) {
            container.getChildren().add(
                    new Button(
                            "Hello"
                    )
            );
        }

        primaryStage.setScene(new Scene(root,300.0,250.0));
        primaryStage.show();
    }
}

Resize the window to be only slightly larger than the content and scroll. The scroll speed should be very very slow.

I am pretty sure the problematic code is in: https://github.com/javafxports/openjdk-jfx/blob/develop/modules/javafx.controls/src/main/java/javafx/scene/control/skin/ScrollPaneSkin.java#L896

In particular this modifies the scroll speed based on the total size of the container - but does not take into account the difference between the size of the viewport and the size of the container.

I think something similar to the following would give a more consistent scroll speed:

vPixelValue = vRange / (nodeHeight - contentHeight);
mudiadamz commented 5 years ago

Yes i think the Scrollpane speed is very very slow compare to Swing or any other app, i think its speed must be constant regardless how small or big the content height. I feel frustrated that i need to scroll like thousands times which in other app that has similar size can be scroll with only 2 scrolls.