• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JTree reload question, AGAIN

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, this question has been asked mutliple times in different varients and forms. So here goes my version because after searching Javaranch and google for 2 days, I can't seem to find a valid answer.
I have a JTree. I build the Tree through a DefaultTreeModel which I have over-ridden. All my values in the Tree come from a databse. Each leaf node is a CustomObject I have created which holds all the relevent information about the leaf object. That's all fine and dandy.
Now, there are various operations that can be performed on the tree leaf objects. Any one of these operations causes the database information to change and the location of the leaf on the tree to change.
Since this app runs on several PC's, the easiest way for me to pick up all the new data is to reload the Tree Model. The problem is that this collapses my Tree. I need the tree to stay expanded to the degree that the user had it before changing information. But the tree also needs to reflect to moves and changes of the leaf nodes.
I tried using a TreePath to store the expanded state of the Tree, but it saves the expanded state with the leaf nodes in their original places instead of them being moved.
Any ideas, suggestions, or comments are welcome to help me solve my problem.
Thanks.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hiya,
One possible approach is to get all the leaf nodes (which are DefaultMutableTreeNodes ?), and throw the buggers into a vector. On second thought, get each of their TreePath's and throw THEM into a vector, instead. Then once the model is loaded, pull the TreePaths outta the vector and iteratively expand each one (using getLastPathComponent I think?).
Hope this helps, it's not pretty but might get you functional until a better solution can be investigated ....
Eric
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I have actually been playing around with use the Observable and Observer classes. I think my model is different from most, because I not just adding and removing nodes and I NEVER have to change the name of the node itself. I use a custom object for my leaf nodes, and the properties of that object is what changes and sometimes, the location of that node in the tree. But it never gets removed from the tree all together. So that is where I am having problems.
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic