aspose file tools*
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
Author

JTree and leaf nodes

Brian Knight
Greenhorn

Joined: Jun 02, 2003
Posts: 16
Hi,
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
Brian
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

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
Hi
I had the following situation
root
-node1
-----node1leaf
-node2
-----node2leaf
-node3
-----node3leaf
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.
Chris
[ November 25, 2003: Message edited by: Chris Brat ]
[ November 25, 2003: Message edited by: Chris Brat ]

SCJP 1.2, SCJP 5, SCBCD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTree and leaf nodes