wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes JTree doesn't return expected value when calling tree.isVisible(treePath) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree doesn Watch "JTree doesn New topic
Author

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

Brady Diggs
Ranch Hand

Joined: Jun 26, 2008
Posts: 42
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...



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18908
    
    8

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

Joined: Jun 26, 2008
Posts: 42
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

Joined: Jun 26, 2008
Posts: 42
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
Bartender

Joined: Oct 14, 2005
Posts: 18908
    
    8

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
Bartender

Joined: Oct 14, 2005
Posts: 18908
    
    8

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

Joined: Jun 26, 2008
Posts: 42
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

Joined: Jun 26, 2008
Posts: 42
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

Joined: Jun 26, 2008
Posts: 42
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

Joined: Jun 26, 2008
Posts: 42
Is that it? Have I run out of help credits?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18908
    
    8

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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

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

Patience is a virtue.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree doesn't return expected value when calling tree.isVisible(treePath)