Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding items too fast causes scroll when item list is empty #86

Open
vonkez opened this issue Feb 8, 2021 · 1 comment
Open

Adding items too fast causes scroll when item list is empty #86

vonkez opened this issue Feb 8, 2021 · 1 comment

Comments

@vonkez
Copy link

vonkez commented Feb 8, 2021

Adding items too fast to item list of a VirtualFlow causes scroll if the item list is empty. Waiting few milliseconds after adding first item fixes the problem. Also calling visibleCells() method after adding first item fixes the problem but I don't know if its about time it takes or something else.

Demo:

public class Main extends Application {
    ObservableList<Integer> items = FXCollections.observableArrayList();
    VBox vbox = new VBox();
    Button add30Buttton = new Button("add 30");
    Button add1Button = new Button("add 1");
    Button removeAllButton = new Button("remove all");

    VirtualFlow<Integer, ?> virtualFlow = VirtualFlow.createVertical(items, i -> Cell.wrapNode(new Label(i.toString())));
    VirtualizedScrollPane<VirtualFlow<Integer, ?>> scrollPane = new VirtualizedScrollPane<>(virtualFlow);

    @Override
    public void start(Stage stage) {
        add30Buttton.setOnAction(event -> {
            items.add(0);
            // virtualFlow.visibleCells(); // uncommenting this fixes the problem
            for (int i = 1; i < 29; i++) { items.add(i); }
        });
        add1Button.setOnAction(event -> items.add(999));
        removeAllButton.setOnAction(event -> items.clear());

        VBox.setVgrow(scrollPane, Priority.ALWAYS);
        vbox.getChildren().addAll(add30Buttton, add1Button, removeAllButton, scrollPane);

        Scene scene = new Scene(vbox, 300, 400);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

@Jugen
Copy link
Contributor

Jugen commented Mar 23, 2021

I'm not sure, but it may be that this is by design ?

Consider that if you populate an empty list then it's "natural" to show the last item added (so scroll down),
but if there's already content then it makes "more sense" to stay where you are (so no scroll).

However there certainly are scenarios where it's equally valid to have the opposite type of behavior from this.
So maybe some API can be added to specify the desired behavior. Any ideas ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants