Hello,
I have a simple beginner's problem, and I'd greatly appreciate some advice. I have a JTree in which the leaf nodes have been assigned a class using .setUserObject(). This allows me to fetch the object using .getUserObject when my TreeListener is triggered and perform some actions on the class after casting. My problem is that adding the userObject eliminates my control over the displayed text. I've created a extended version of DefaultCellRenderer to deal with this problem (using the JTree tutorial as a template), but I need to be able to fetch information from the UserObject to format the appropriate text for the leaf nodes. Any advice on how to accomplish this would be much appreciated.
Thanks!
P.S. below is the skeleton of the extended renderer... basically copied from the JTree tutorial.
class MyRenderer extends DefaultTreeCellRenderer {
public MyRenderer() {
}
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
if (leaf) {
this.setText("This part works... but how to fetch the leaf-specific info to add the correct text???");
}
return this;
}
}