Run code to reproduce. There are a lot of unexpected invocations
@Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
ListView list = new ListView();
list.setCellFactory(new Callback<ListView, ListCell>() {
@Override
public ListCell call(final ListView param) {
return new ListCell() {
@Override
protected void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
System.out.println("Update item invoked " + getIndex());
}
};
}
});
root.getChildren().addAll(list);
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
////output
Update item invoked -1
Update item invoked 0
Update item invoked 0
Update item invoked -1
Update item invoked -1
Update item invoked -1
Update item invoked 0
Update item invoked 0
Update item invoked -1
Update item invoked 1
Update item invoked 1
Update item invoked -1
Update item invoked 2
Update item invoked 2
Update item invoked -1
Update item invoked 3
Update item invoked 3
Update item invoked -1
Update item invoked 4
Update item invoked 4
Update item invoked -1
Update item invoked 5
Update item invoked 5
Update item invoked -1
Update item invoked 6
Update item invoked 6
Update item invoked -1
Update item invoked 7
Update item invoked 7
Update item invoked -1
Update item invoked 8
Update item invoked 8
Update item invoked -1
Update item invoked 9
Update item invoked 9
Update item invoked -1
Update item invoked 10
Update item invoked 10