• 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

getting first child after root in JTree

 
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
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

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A breakthrough, but still seems like too much code. Thank you for your help.

 
reply
    Bookmark Topic Watch Topic
  • New Topic