Adding items too fast causes scroll when item list is empty
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);
}
}

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 ?