tags:

views:

48

answers:

1

From the Java API, it seems that nodes of a JTree are instances of TreeNode. In addition, all TreePaths returned seems to be instances of TreeNode. So, why are TreePaths represented by Object[] instead of TreeNode[]? This give raise to inconvenience when using these classes.

Thanks.

+2  A: 

See this explanation from the Java tutorial:

Interestingly, the TreeModel interface accepts any kind of object as a tree node. It does not require that nodes be represented by DefaultMutableTreeNode objects, or even that nodes implement the TreeNode interface. Thus, if the TreeNode interface is not suitable for your tree model, feel free to devise your own representation for tree nodes. For example, if you have a pre-existing hierarchical data structure, you do not need to duplicate it or force it into the TreeNode mold. You just need to implement your tree model so that it uses the information in the existing data structure.

akf