FadelMS
FadelMS

Reputation: 2037

Adding custom propery to a JTree node

I need to store some data in a JTree node. Is it possible to add a custom property to a node to hold my data?

Upvotes: 3

Views: 1256

Answers (1)

Tom
Tom

Reputation: 44881

You can create a node class that extends say DefaultMutableTreeNode with a property for your data.

public final class MyDataNode extends DefaultMutableTreeNode {
    private final MyData myData;

    public MyDataNode(MyData myData) {
        this.myData = myData;
    }

    public MyData getMyData() {
        return myData;
    }
}

Upvotes: 7

Related Questions