Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes JTree and leaf nodes 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 and leaf nodes" Watch "JTree and leaf nodes" New topic

JTree and leaf nodes

Brian Knight

Joined: Jun 02, 2003
Posts: 16
Does anyone out there know how to stop a jtree showing it's leaf nodes. I want to create a menu system, similar to a file explorer, but I don't want the tree to display the child nodes, instead I want these to be displayed in a seperate panel.
I have done some searching in the code, and have not been able to come up with anything so any help would be appreciated.
Thanks in advance
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

I'd think your model is what you want to look at. It tells the View what to display. For example, you probably don't want to display files in the tree, so don't add them to the model. When someone selects a particular directory you can scan it and display all its contents, files and directories, in the next frame.

[How To Ask Questions On JavaRanch]
Chris Brat
Ranch Hand

Joined: May 22, 2003
Posts: 108
I had the following situation
I hid the root (it was just my defined starting point to add my nodes).
Each node had the text data that I wanted the user to see and each node had one leaf that contained the nodes IDKey (unique identifier).
Since I didnt need the leaves to be shown, I could restrict this by setting the click count to 0 or -1 (sorry cant remember for sure which one). This prevented the nodes from being expanded, but allowed me to retrieve the code from the leaf (when selected) and then set up another separate screen with the relevant details according to the code.
It might not be the worlds most attractive solution but hey... it works like a beauty.
[ November 25, 2003: Message edited by: Chris Brat ]
[ November 25, 2003: Message edited by: Chris Brat ]

I agree. Here's the link:
subject: JTree and leaf nodes
It's not a secret anymore!