I am working on customizing a closed source client application. It has a tree in the UI and exposed only a method to get the selected node. It returns a subclass of TreeNode. And there is no way to get a reference to the parent tree. Now i want to expand the selected node upto its leaves.
Is there any way to get a reference to the JTree component from a DefaultMutableTreeNode? I am planning to use the JTree.expandPath() but I only have the reference to the treenode.
I’m new to Swing and any suggestions to achieve this are welcome.
Actually, only the JTree is aware of the expansion state, there is no such information in the TreeNodes. The TreeNodes are on the “model” side, and have no pointer on the JTree (at least not default ones, you can of course make your own with a reference, but it breaks a bit the pattern).
You should reconsider the place where you want to make this expansion for a place in which you have access to the JTree (provide maybe more details about your context, to know more what you want to do, and in which circumstances).