• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JTree, adding and removing nodes contained in a master tree

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
James Wagner
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic