I need to display the javafx tree table with values read from XML file. I am able to do it as shown below,
I am able to add color to the combo box as shown
But when I collapse the tree the color which is set still remains the same, as shown here
How can I change it back to normal?
This is the piece of code I tried for changing color to the combobox
where dojColumn is a column to display "Status"
dojColumn.setCellFactory(new Callback<TreeTableColumn<TestSet, String>, TreeTableCell<TestSet, String>>(){
@Override
public TreeTableCell<TestSet, String> call(TreeTableColumn<TestSet, String> param) {
// TODO Auto-generated method stub
return new ComboBoxTreeTableCell<TestSet,String>(list){
public void updateItem(String status,boolean empty) {
super.updateItem(status, empty);
int currentIndex = indexProperty().getValue() < 0 ? 0: indexProperty().getValue();
String clmStatus = dojColumn.getCellData(currentIndex);
if(!empty) {
if (status == null || empty) {
setStyle("");
}
else if (clmStatus.equals("Passed")) {
setTextFill(Color.BLACK);
//setStyle("-fx-font-weight: bold");
setStyle("-fx-background-color: green");
setText(clmStatus);
} else if (clmStatus.equals("Failed")){
setTextFill(Color.BLACK);
//setStyle("-fx-font-weight: bold");
setStyle("-fx-background-color: red");
setText(clmStatus);
} else if (clmStatus.equals("NotRelevant")){
setTextFill(Color.BLACK);
// setStyle("-fx-font-weight: bold");
setStyle("-fx-background-color: blue");
setText(clmStatus);
}
}
}
};
}
});
can anyone help me with this. Thanks in advance.



emptyisfalseso should be the condition of the first innerif). Furthermore doing the index logic outside of theifs and dealing with empty cells with a tenary expression there seems weird. Just put it at a point where you know the cells is non-empty. Furthermore clmStatus shouldn't be different from status afaik. - fabianxyzProperty().getValue()can be usually writen asgetXyz()(orisXyz()forBooleanPropertys) which I personally prefer for being more concise. - fabian