I am using class VisualNode below as my user object
Ok, so I am using my own renderer because this is a compound node with JButtons, JTabbedPane, JTextArea in a Box.
When I create the node, I do a:
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(new VisualNode("My Name"));
parentNode.add(childNode);
I have 3 questions:
1) DefaultTreeCellRenderer extends JLabel, but VisualNode contains several JComponents. So is it correct for MyCellRenderer to extend DefaultTreeCellRenderer?
2) How do I access the user object? In the renderer, I want to be able to get this user object so that I can return the Box component.
3) What is the parameter "Object value" for a Compound node? If I add the Editor, how will it know which it stands for? (the title or the details)
Originally posted by Paul Clapham:
Here's the tutorial on JTree:
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
It includes some examples of TreeCellRenderers, which are what you are asking about. Most of the examples you'll find have the renderer extending JLabel, because commonly a JLabel is sufficient to render a tree node. But in your case the renderer will have to be some other component, maybe JPanel or a customized subclass.