• 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:

Expand Lazy Loaded JTree

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a Lazyily loaded JTree but I am facing some problems.

I have a JTree which I load lazily using database query (each node). I have a button on the screen and when user clicks the button I perform some insert/update/delete in database and then add the model back in Jtree with only root and its immediate children using an SQL (this collapses the tree and selection and all expanded nodes collapse which is expected since it is a lazily loaded tree)

What I want to accomplish is before user clicks button to insert/update/delete, I read all the expanded state and save it in memory then when I re-initialize the Jtree I loop through those expanded children and call jtree.expandPath but it does not expand the nodes .

I even added a TreeWillExpandListener and in treeWillExpand event I added code to get the children of the node from database and I see that query does get executed to get the childreen but JTree still shows up as collapsed.

I really need your help. Please advise. Here is the code snippet.

 
Shams Pakistan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the solution.

Need an equals method and hashCode in my NodeData class, problem was internally after setting the new Model when I was trying to expand the path the equals returned false as default implementation of equals does a "shallow compare" i.e. only compares references, I had to override the hashCode and equals method and did a "Deep compare" in equals method.

Thanks
 
permaculture is largely about replacing oil with people. And one tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic