Flowless
Flowless copied to clipboard
GetFirstVisibleIndex returns same values before and after scrolling
This is my test code:
public class FlawTest extends Application {
private static class FlowRow implements Cell<Integer, Node> {
private Integer rowIndex;
private final Label label = new Label();
private final HBox hBox = new HBox(label);
public FlowRow(Integer rowIndex) {
this.rowIndex = rowIndex;
label.setText(String.valueOf(rowIndex));
}
@Override
public void updateItem(Integer item) {
rowIndex = item;
if (item == null) {
label.setText("");
} else {
label.setText(String.valueOf(rowIndex));
}
}
@Override
public Node getNode() {
return hBox;
}
@Override
public boolean isReusable() {
return true;
}
}
private VirtualFlow<Integer, FlowRow> flow;
private ObservableList<Integer> rows;
@Override
public void start(Stage primaryStage) throws Exception {
List<Integer> list = new ArrayList<>();
for (var i = 0; i < 100000; i++) {
list.add(i);
}
rows = FXCollections.observableList(list);
flow = VirtualFlow.createVertical(rows, row -> new FlowRow(row));
VirtualizedScrollPane<VirtualFlow<Integer, FlowRow>> scrollPane = new VirtualizedScrollPane<>(flow);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
var scrollButton = new Button("Scroll");
scrollButton.setOnAction(e -> {
System.out.println("Before scrolling first cell index: " + flow.getFirstVisibleIndex());
flow.scrollYBy(flow.getHeight());
System.out.println("After scrolling first cell index: " + flow.getFirstVisibleIndex());
});
VBox root = new VBox(scrollPane, new HBox(scrollButton));
Scene scene = new Scene(root, 400, 300);
primaryStage.setTitle("Flaw Test");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
If you push button you will get the following output:
Before scrolling first cell index: 0
After scrolling first cell index: 0
Before scrolling first cell index: 17
After scrolling first cell index: 17
I tried:
scrollButton.setOnAction(e -> {
System.out.println("Before scrolling first cell index: " + flow.getFirstVisibleIndex());
flow.scrollYBy(flow.getHeight());
Platform.runLater(() -> System.out.println("After scrolling first cell index: " + flow.getFirstVisibleIndex()));
});
but the result was the same.