I have this JTree:
IhavethiscodethatreturnsallnodesofJTree
:
publicvoidprint(){recurse((TreeNode)jTree2.getModel().getRoot());}publicvoidrecurse(TreeNodetheNode){System.out.println("1-- " + theNode);
for (Enumeration theChildren = theNode.children(); theChildren.hasMoreElements();) {
recurse((TreeNode) theChildren.nextElement());
}
}
Output from this code:
1-- JTree
1-- colors
1-- blue
1-- violet
1-- red
1-- yellow
Is there a way to adapt this jTree print code but only with the selected nodes?
The following code returns an Objects with paths:
TreePath[] checkedPaths = checkTreeManager.getSelectionModel().getSelectionPaths();
for (TreePath s : checkedPaths) {
System.out.println(s);
}
}
In the case of JTree that I posted the output of the previous code is:
[JTree, colors, blue]
[JTree, colors, violet]