Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Best way for modeling a JTree?

Thread view: 
Nop.Lists@gmail.com - 18 Dec 2007 05:58 GMT
G'day,
I would be very grateful for insights considering modeling a JTree.

Background
=========
I am learning swing and try to build various kinds of trees.
One kind of tree I am dealing with is the filesystem tree (where my
underlying objects are java.io.File).
Another kind are XML files (where the underlying objects are e.g.
org.jdom.Entity).
Yet another kinds are trees of user defined objects.

The Question
==========
I have experienced with  3 methods for building the trees:
1. Use DefaultMutualTreeNode and put your object in teh UserNode
2. Define an overlying structure that extends the
DefaultMutualTreeNode and mirrors my domain.
   Example: have a XMLEntity, XMLComment, XMLPI etc. wich correspond
to the entities of JDom.
3. Define a model over my domain (in the example of a filesystem tree
my model is based on java.io.File). I define all operations on the
model.

What would you consider as the best way and why?

Thank you very much for your insights!
nop.lists
Piet Blok - 18 Dec 2007 06:25 GMT
Nop.Lists@gmail.com wrote in news:9bcf6229-6519-4b06-9e05-06925c6c7189
@e23g2000prf.googlegroups.com:

> G'day,
> I would be very grateful for insights considering modeling a JTree.
[quoted text clipped - 24 lines]
> Thank you very much for your insights!
> nop.lists

Hi,

1) I would definitely write a custom TreeModel and not
extend or use DefaultTreeModel.
2) I would consider the possibility to NOT define ALL
operations in that model, but, in certain cases, to
have the nodel listen to events fired from the domain
itself. (For File objects I can't think instantly of
an example of a possible event, but other domains may have).

As a sample, you might have a look at my abstract tree model

http://www.pbjar.org/docs/src/org/pbjar/swing/AbstractTreeModel.java

And an implementation for DOM trees

http://www.pbjar.org/docs/src/org/pbjar/dom/DOMTreeModel.java

Hope this helps

Piet


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.