When I use JTree, by default it is in a collapsed state. How can I make it initially expanded?
Sandip Chitale I think the first level is always expanded.The trick is to compute the TreePaths. The general algorithm would be to compute the leaf nodes and force expansion of each of the leaf nodes unique parent.
To have every level expanded you could use -
public void expandPath(TreePath path) Ensures that the node identified by the specified path is expanded and viewable. Parameters: path - the TreePath identifying a nodeof javax.swing.JTree.
If your tree is made out of a DefaultMutableTreeNodes then you can get the enumeration of all the nodes and thus compute the TreePaths easily.