I need to set a color of row in TreeTable based on column value. Although I have already found two answers for such a question: javafx adding color to row based on column value
Javafx: TableView change row color based on column value
,unfortunately I can not find a way how to implement it in my code? From code below TreeTable works OK. Let's say I want now to click button "check staff" and update TreeTable with 2 contitions: 1 - mark green color rows where Managers name is "John"
2 - mark yellow color rows where Days Absence are > 4
Can somebody explain how to do it in my code?
public void showStaffInTreeTable(){
ArrayList<Employee> johnStaff = new ArrayList<>(Arrays.asList(new Employee("1", "secretary", "1"),
new Employee("2", "cleaner", "2")));
ArrayList<Employee> amandaStaff = new ArrayList<>(Arrays.asList(new Employee("3", "driver", "0"),
new Employee("4", "mechanic", "5")));
ArrayList<Manager> allStaff = new ArrayList<>(Arrays.asList(new Manager("John", johnStaff),
new Manager("Amanda", amandaStaff)));
TreeTableColumn<Staff_DTO, String> columnManager = new TreeTableColumn<>("Manager");
TreeTableColumn<Staff_DTO, String> columnStaffId = new TreeTableColumn<>("Id");
TreeTableColumn<Staff_DTO, String> columnStaffWorkplace = new TreeTableColumn<>("Workplace");
TreeTableColumn<Staff_DTO, String> columnStaffAbsence = new TreeTableColumn<>("Days Absence");
columnManager.setCellValueFactory(new TreeItemPropertyValueFactory<>("managersName"));
columnStaffId.setCellValueFactory(new TreeItemPropertyValueFactory<>("id"));
columnStaffWorkplace.setCellValueFactory(new TreeItemPropertyValueFactory<>("workplace"));
columnStaffAbsence.setCellValueFactory(new TreeItemPropertyValueFactory<>("daysAbsence"));
treeTableStaff.getColumns().addAll(columnManager, columnStaffId, columnStaffWorkplace, columnStaffAbsence);
TreeItem root = new TreeItem(new Staff_DTO("", "","",""));
for (Manager manager: allStaff){
TreeItem managerItem = new TreeItem(new Staff_DTO(manager.getManagersName(), "","",""));
for (Employee employee: manager.getManagersStaff()){
managerItem.getChildren().add(new TreeItem<>(new Staff_DTO("",employee.getId(), employee.getWorkplace(), employee.getDaysAbsence())));
}
root.getChildren().add(managerItem);
}
treeTableStaff.setRoot(root);
anchorPaneTreeTableStaff.getChildren().add(treeTableStaff);
}
public void buttonCheckStaff(){
}