Answer the question
In order to leave comments, you need to log in
How to change color in table in JavaFX depending on conditions?
The data is unloaded from the database, so I found such a solution for unloading data and changing the color.
private void styleRowColor() {
Callback<TableColumn<ModelTableDriversLogArea, String>, TableCell<ModelTableDriversLogArea, String>> cellFactory
=
new Callback<TableColumn<ModelTableDriversLogArea, String>, TableCell<ModelTableDriversLogArea, String>>() {
@Override
public TableCell<ModelTableDriversLogArea, String> call(final TableColumn<ModelTableDriversLogArea, String> param) {
final TableCell<ModelTableDriversLogArea, String> cell = new TableCell<ModelTableDriversLogArea, String>() {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
setText(null);
} else {
setText(item);
TableRow<ModelTableDriversLogArea> row = getTableRow();
if (row.getItem().getDivision().equals("-")) {
row.getStyleClass().clear();
setStyle("-fx-background-color: green");
}
}
}
};
return cell;
}
};
col_divisionDriversAreaLog.setCellFactory(cellFactory);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question