I have a column in a table view and i want: Green font if i write "OK", red font if i write "KO". The problem is that i try to modify this value in the method "setCellFactory" but it doesn't work because the String have all the same color (red or green) that is the color of the last String... For istance if my last value is "KO" all the String in my column will be red. How can i do? Thank you for the help!
reader.getSampleController().xmlMatch.setCellFactory(new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn param) {
TableCell cell = new TableCell() {
@Override
public void updateItem(Object item, boolean empty) {
if (item != null) {
setText(item.toString());
}
}
};
cell.setAlignment(Pos.CENTER);
if (result.match().equals("OK")) {
cell.setStyle("-fx-text-fill: green; -fx-font-weight:bold;");
} else if (result.match().equals("N/A")){
cell.setStyle("-fx-text-fill: black; -fx-font-weight:bold;");
}else{
cell.setStyle("-fx-text-fill: red; -fx-font-weight:bold;");
}
return cell;
}
});