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

creating jTree from objects

 
yu po
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all! i am new in swing and i have a question...

i have for example vector of car objects.
lets say that car include the fields: model, company year.

i would like to create a jTree that each node of his root represent a car.

that the sub-root will be the car's model and his sub-nodes are leafs that each of them is the car's company and car's year.

i know that i need to use somehow the jTree model and the cell renderer but how?

i want to be able to add new cars to the jTree how i do it?

thanks a lot!!! i hope you can help me
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> i hope you can help me

I could, but I don't spend time helping cross-posters

http://forums.java.net/jive/thread.jspa?messageID=469120&tstart=0
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a hard way and an easy way.

The hard way: create a custom TreeModel implementation around a List<Car>.

The easy way: create a method that turns a Car into a TreeNode (DefaultMutableTreeNode), then use DefaultTreeModel to add the TreeNode.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another cross post
http://forums.sun.com/thread.jspa?threadID=5438634
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic