Skip to content

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

Description

@vonkez

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);
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions