Well, this is screwed up! Or at least it seems so.
Now here's an example:
Now, as you can see I got 2 exactly the same trees! The little
test here shows that even if they have the same structure, I cant get the path from tree #1 and use that on tree #2!!! (??) I was wondering WHY? and how this can be easly solved! The reason I wanna be able to do this is because three #1 is a more complex tree while the other (tree #2) is supposed to be used to be able to select some particual node in that complex #1 tree. I had in mind to then build a tempurary tree to get the TreePath out, since apparently:
jt.setSelectionPath(tp.pathByAddingChild(node);
aint working either!! Which should be damn much nicer (and faster)!
(but please feel free to make this version work! I could have missed something with some object)
Say I got this in tree#1:
/
| -- demo
| | -- file.zip
| | -- file2.zip
| | -- dir2
| -- {dir3}
where {dir3} indicates that dir3 is now selected. Now, if I wanted to add some node to dir2 there is problem. I couldnt really find anything usefull to help me out with that! I NEED the TreePath to that node (dir2). There really just are:
TreePath pathTree = jt.getSelectionPath();
But that assumes you have selected dir2! Annoying. So, I thought (which is WAY better than make
java select it by.. say the setSelectionRow(int row); that I could create the path with the "demo" + adding the "dir2" node. Thus do the: jt.setSelectionPath(tp.pathByAddingChild(new DefaultMutableTreeNode("dir2");
But ofcource that isnt working.
Then I thought, I could recreate a new temptree with just the nodes needed. /demo/dir2 in this case and get the path from that (since I here can use the jttemp.getRowCount(); and select the last one (since its only "one" tree, where I wanna select the last child so to speak))
So, to do: TreePath tptemp = jt.getPathForRow(jt.getRowCount());
And voil�! Well, so I thought. Didnt work to use that tptemp for tree #1!
Got damn its frustrating!
Anyone here got time to help me out? Hope this all made sence.. Basicly, what it comes down to. How do I get a TreePath to /demo/dir2 !! that works so I can use that to insert nodes into that if the node itself isnt even selected!? I really wanna avoid using getSelectionPath()!!
Thanks,
Ace