I need litle help here to get started in right direction. (sort of lost somewhere.).
I am trying to display an object in JTree component with all its premitive data as well as any other user-defined object it may contain. Object which i am getting doesn't have to do anything with specific tree interfaces, they are simple POJO's which can contain number of user-defined objects in them. (sort of debugging view of an object). I can get all the information about object using my reflection utility. which can provide me every information in string form.
i just want to create a tree model for that object. this is what i have done using HashTable with JTree.
.....code to access this model and create JTree is as follows
Problem with this approach. JTree constructor which takes the hashtable can not show root node. and only 1-level (up to one level expanding of node) is supported.
can some one help me out here.
-------------------------------<br />you can't move ahead, unless you try for it.
JTree depends on its TreeModel. To make your own TreeModel you would have your custom model class implement the TreeModel interface. You can look at the source code of DefaultTreeModel to get some ideas about implementing the methods defined in the TreeModel interface. Another option is to use a DefaultTreeModel in which these methods are already implemented for you. You would need to make up a class that implements the TreeNode interface to be used by the DefaultTreeModel. For ideas about implementing the methods defined in this interface you can look at the source code for the DefaultMutableTreeNode class. Another option is to use DefaultMutableTreeNode for a DefaultTreeModel. The userObject is the user-defined object that is used in the DefaultMutableTreeNode. This way most of the work of dealing with model, nodes, and events is taken care of for you. You might put your custom object together into a JTree form along these lines: