Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am unable to understand how to use setCellFactory method to format individual TreeItems.

I have a class

Java
public class Bag {
public String caption,assignment="";
Boolean eval;
public Set<Vertex> Nodes = new HashSet<Vertex>();
public Vector<Bag> ChildBags = new Vector<Bag>();

 @Override
public String toString()
{
    return assignment+ " " +caption;
}
}

Here's my css file:

CSS
.true{
    -fx-text-fill:#33cc00 ;
}
.assignment{
    -fx-text-fill: #0033cc
}

I have a treeview of bags. I want to color to green the caption ( the toString() method returns ) of all those nodes whose eval property is true. and assignment string which toString() method returns for all the nodes should be blue.

How can I do so?

Thanks.

What I have tried:

Java
TreeView<Bag> treeView = new TreeView(root);

treeView.getStylesheets().add("format.css");

PseudoClass childPseudoClass = PseudoClass.getPseudoClass("child");

treeView.setCellFactory(tv -> new TreeCell<Bag>() {

    @Override
    protected void updateItem(Bag item, boolean empty) {
        super.updateItem(item, empty);
        if (empty || item == null) {

        } else {
            if(item.eval==true){
            //how to assign different style to different components
            }


        }

}
});
Posted
Updated 16-Apr-19 5:11am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900