• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTree doesn't return expected value when calling tree.isVisible(treePath)

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone
I am trying to keep a node expanded programatically but am having no luck.
I first set a nodePath to be expanded. Then I get its children.
I also want to check to see if the children are expanded. If they are, then I want
to keep them expanded as well.
The way I am trying to do this is checking to see if the children have children.
If the grandchildren are visible, the keep the childNode expanded.

The only problem with this otherwise simple solution is that when I call
tree.isVisible(grandChildPath) it returns false, when in fact the childNode is expanded
and the grandChildren are visible.
Please take a look and see if I am doing something terrible wrong.

The "e" on line 3 is a TreeModelEvent...



 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It isn't obvious to me that the child node is expanded. I don't see anything in your code which tests whether it is expanded, and I don't see anything which makes it expanded. Hopefully you weren't referring to line 7 of the code you posted.
 
Brady Diggs
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul...
I was reading one of your posts on Sun Forums earlier.
The childNode is supposed to be expanded on the last line, line 17,
based on isChildExpanded (which is determined by whether or not
the grandChildPath is visible).
Make sense?
 
Brady Diggs
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The idea here is to expand, or keep expanded, the child node if it is already expanded.
The way I'm testing whether or not it is expanded is to see if the grandChildPath is visible.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That makes sense. So if the child isn't expanded, then the grand-child won't be visible, right? And therefore you wouldn't be expanding the child.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brady Diggs wrote:The idea here is to expand, or keep expanded, the child node if it is already expanded.


I'm not sure that this part makes sense though. You're saying, if the child node is expanded, then make it expanded? And if it isn't expanded, then leave it that way? Seems like you want to do nothing in either case.
 
Brady Diggs
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. That is the case, but if I do nothing, the tree collapses
as a matter of course. The code is old and not that well developed.
 
Brady Diggs
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It collapses when I do nothing, so my thinking was to setExpandedState to true
if the grandchildren are visible. Otherwise, the assumption is that it isn't expanded,
so call setExpandedState(childPath, false).
 
Brady Diggs
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just tried running it with the grandChild stuff removed
and the setExpandedState removed.

Here is the code:



The childNode collapses. This is the behavior I am trying to avoid.
 
Brady Diggs
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that it? Have I run out of help credits?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brady Diggs wrote:Is that it? Have I run out of help credits?


Sorry, I don't understand this. Can you clarify? Whatever it is doesn't seem to have much to do with the original question.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brady Diggs wrote:Is that it? Have I run out of help credits?


Patience is a virtue.
reply
    Bookmark Topic Watch Topic
  • New Topic