This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi, basically what I am working on is there is one JTree that always contains the full tree (depth 2) for a particular dataset. There is next to this a JTree that is initially empty (except for a root) to which the user can add or remove nodes from the master tree arbitrarily.
If the user clicks on a node in the master tree, the "Select" button is enabled, any selections in the subset tree are cleared, and the user can add to the subset tree, if the user selects a node in the subset tree, the "Unselect" button is enabled, any seletions in the master tree are cleared, and the user can remove from the subset tree, but none of this makes any change to the master tree.
Will want to be able to work at any depth, such that clicking the root node in the master tree and then select will transfer the entire tree to the subset tree, selecting a mid-level node will transfer that node and all of its children to the subset, and selecting a leaf node will transfer only that leaf node (and its parent if it's not already there) to the subset tree. Right now I am focusing on the second of the three problems.
I am finding that doing it once through things work ok, you can add a node and then remove it from the subset tree. Trying to add a second node, or re-adding the original node after it has been added and removed once, seems to change the model yet I cannot seem to get it to display, can't really figure out what would be different in the logic flow the second time around.
Here is the method that is called once the "Select" button has been clicked, and it is determined which node in the master tree was selected (which is passed as the argument nodeToAdd. Thanks if you can shed any light on this.
Joined: Jun 25, 2007
Hi, after further playing around with it just a quick follow-up to maybe provide another clue as to problems with behaviour, if I keep the subset tree that i am adding to collapsed, I can add nodes to it to my heart's content, and then when I expand it I can see everything that was added. It is only after I expand it that nodes added subsequently are not showing up in the display on the subset tree.
Still not sure what I could do to ensure nodes are added and displayed properly on the tree when it has already been expanded.