I got a very strange bug in a JavafX application. A cell should be conditionally formatted due to a boolean. If you scroll up and down the ListView, however, the various entries are highlighted in color. However, there is only one entry in the entire list that should be marked.
serialNumberList.setCellFactory(lv -> new ListCell<ListData>() {
@Override
protected void updateItem(ListData c, boolean empty) {
super.updateItem(c, empty);
if (empty) {
setText(null);
} else {
setText(c.name);
}
System.out.println(c);
if (c != null && c.colored) {
setStyle("-fx-background-color: #33CEFF");
}
}
});
The ListData
Class:
String name;
boolean colored = false;
int id;
public ListData(String name, boolean colored, int id) {
this.name = name;
this.colored = colored;
this.id= id;
}
The result before scrolling:
The result after scrolling a few times: