This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting first child after root in JTree

 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am at my wit's end in trying to find away to know if a user has clicked on the first child of a JTree. My tree has directories from A to Z. Inside
those dorectories are other directories. I want to be able to disable the popup menu items if the user clicks on a dir from A to Z. I could just use the String class to find this out except
sometimes there is a directory inside one of the leter directories that can start with just a single capital letter. I think it should be easier just to the find the child directories of the ROOT.
I cannot cast a node to Default MutableTreenode because I am suing the JTree provide by TrueZip classes for file encryption. I have tried playing with the following lines of code for an hour or so:

 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isaac Hewitt wrote:I think it should be easier just to the find the child directories of the ROOT.

Yes. That should be the first step. Then you can see if the node just selected was one of them.
I cannot cast a node to Default MutableTreenode because I am suing the JTree provide by TrueZip classes for file encryption.

But that's not quite the point. You need to get the children of the root, no matter what class is implementing them. Surely this JTree version has a way to do that?

Edit: Actually you don't need to find the children of the root. What you need (I think) is simply to ask whether the parent of the selected directory is the root of the tree.
 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Edit: Actually you don't need to find the children of the root. What you need (I think) is simply to ask whether the parent of the selected directory is the root of the tree.

I previously had that idea too, but was not able to find the way to do this either. I want to be able to detect this so I can disable the rename command in the menu item so the user cannot rename the directories from A to Z. So it's back to the drawing board.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not? Doesn't your node class have a getParent() method?

(Note that nobody out here knows anything about the classes you're using. So when you don't provide any details about them, it's hard to say much.)
 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The above code never gets to the print out "eureka" obvioulsy because the Strings don,t match. I am however getting close to cracking it albeit clumsily.
 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A breakthrough, but still seems like too much code. Thank you for your help.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic