It's not a secret anymore!
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "creating jTree from objects " Watch "creating jTree from objects " New topic

creating jTree from objects

yu po

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
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10828

Thanks Michael.

Yu Po,
Please read

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

Joined: Oct 27, 2005
Posts: 20279

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.

How To Ask Questions How To Answer Questions
Darryl Burke

Joined: May 03, 2008
Posts: 5115

Another cross post

luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
subject: creating jTree from objects
It's not a secret anymore!