File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Displaying Data in a JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Displaying Data in a JTree" Watch "Displaying Data in a JTree" New topic
Author

Displaying Data in a JTree

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
I have a JTree that is displaying part numbers. I have had a request from users that I also display the description of the part number. Is there a way that I can display 2 columns of data on one tree node? Otherwise, the only other way I know how to do this is to get the description and concatenate it with the part number. Which would cause me problems as I have a popup menu attached to the tree nodes that takes the value of the node (part number) and passes it to another application. How would I be able to tell it that I only want the part number to be passed and not the description?

Thanks for any help!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I suppose the objects in your tree nodes are just Strings containing the part numbers? I would do this:

1. Create a Part object containing the part number and part name. Make the toString() method of Part return the part number and name concatenated, so that's what will appear in the JTree.

2. Change the popup menu to get the part number from the Part object that's in the node.
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Thanks for the response! That makes complete sense to me now. You're awesome!!!
 
 
subject: Displaying Data in a JTree
 
Similar Threads
Vector to Jtree
Expanding a Specific Node in JTree
JTree SubTree
JTree in Browser
JTree