Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying Data in a JTree

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • 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!
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for the response! That makes complete sense to me now. You're awesome!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic