tags:

views:

41

answers:

1

Imagine a collection of objects such as World, Country, Region and City. World contains a list of Country objects, Country contains a list of Region objects etc.

I would like to represent this structure in a JTree and be able to add, remove and move objects around the tree.

Can I easily create a TableModel from this structure? World would be the root object and I would need to perform some object-specific rendering.

Any one know of an appropriate tutorial that goes beyond building a tree from simple text nodes?

A: 

You might start with the examples mentioned in How to Use Trees. You may need profile your code if the intended number of leaf nodes is large. You may want to consider a map as an alternate interface for the uppermost levels. See also the three-part series of articles starting with Creating TreeTables in Swing.

Addendum: Part three in the series cited includes an example TreeTableModelAdapter.

$ ls -1 src/bookmarks/
AbstractTreeTableModel.java
Bookmarks.java
BookmarksModel.java
DynamicTreeTableModel.java
JTreeTable.java
TreeTableExample3.java
TreeTableModel.java
TreeTableModelAdapter.java
trashgod
I looked at those examples already. I know how to build up a tree by adding texts to nodes etc. That is not the problem. In my question I asked how to use an existing model in a tree **with the least effort** (why did you edit that out?) How can I update model and tree? Do I need to add notification to my model or can I add some kind of wrapper to it?
paul
@paul: Reading your revision to the original question, I have nothing better to offer than my answer's first link. The second link has an example of a `TreeTableModelAdapter`.
trashgod
Ok I'll check it out. I had a look at the JFace TreeViewer today and got a bit more traction with that. It'll be interesting to compare...
paul
@paul: It might be worth adding such links to your question for future reference. Sorry if I over-stepped on your title. Your requirements go beyond the simple _How to display a tree of objects in a JTree?_ Maybe append, _beyond basics_?
trashgod