• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Displaying Data in a JTree

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 28413
102
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
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
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response! That makes complete sense to me now. You're awesome!!!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic