I have the following piece of code to update both the color of a column cell and its corresponding row:
calltypel.setCellFactory(column -> {
return new TableCell<CallLogs, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(empty ? "" : getItem().toString());
setGraphic(null);
TableRow currentRow = getTableRow();
//This doesn't work
if(item.equals("a")){
item.setTextFill(Color.RED);
currentRow.setTextFill(Color.PINK);
}
else{
item.setTextFill(Color.GREEN);
currentRow.setTextFill(Color.BLUE);
}
}
};
});
The code segment of 'if' condition doesn't work. I am unable to identify the correct references to objects and also what is the best way to do this.
Thanks!
After many searches i found the answer. You need to set an id for specific row in table and set the color in external css file depending on row id. Here is the example where i change the color of error rows to red. Java code:
CSS file: