My program is changing ListCell
styles based on it's content:
debugListView.setCellFactory(listCell -> new ListCell<String>() {
@Override
public void updateItem(String content, boolean isEmpty) {
super.updateItem(content, isEmpty);
if (isEmpty || content == null) {
setText("");
setStyle("");
} else {
setText(content);
if (content.contains("INFO")) {
getStyleClass().addAll("info", "debug");
} else if (content.contains("WARN")) {
getStyleClass().addAll("warning", "debug");
} else if (content.contains("ERROR")) {
getStyleClass().addAll("error", "debug");
}
}
}
});
This works great but if you scroll through the list the styles get messed up. I'm read about how ListCells
in a ListView
are managed while scrolling and that they are destroyed and recreated everytime and that this could be the problem (https://stackoverflow.com/a/12425646/4469105). Similar to the TableView
sorting problem where TableCell
styles get messed up when sorting columns which seems to get fixed with 8u60 (https://stackoverflow.com/a/11066040/4469105).
Nevertheless I found no workaround for this one. So does anyone have an idea or some keywords?
Thank you in advance!