aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes creating jTree from objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "creating jTree from objects " Watch "creating jTree from objects " New topic
Author

creating jTree from objects

yu po
Greenhorn

Joined: May 09, 2010
Posts: 1
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

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Jul 26, 2007
Posts: 10523
    
    9

Thanks Michael.

Yu Po,
Please read http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Another cross post
http://forums.sun.com/thread.jspa?threadID=5438634


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating jTree from objects