File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTree question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree question" Watch "JTree question" New topic

JTree question

Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
I am building an application that needs to work with some tree-like hierarchical data structure of arbitrary complexity, which will be displayed both as a JTree and as a diagram in the user interface. I was busy trying to think of a way to represent the data I'm working with, but then wondered whether I could scrap that idea and just use JTree to actually hold the data, rather than just represent it on screen?
So, for example, if I create a load of objects of class 'MyEffect', each having properties like name, colour, size, category, can I store these objects in a JTree and use, say, to label the node?
any advice would be gratefully received.

SCJP 1.4,
Sonny Pondrom
Ranch Hand

Joined: Jun 05, 2001
Posts: 128
I am using a JTree for a very complex object and think you should use it. I had to think objectively, I made nodes that handled my data. I then made a TreeModel to handle my nodes and finally a JTree from my TreeModel. I have found all the info is there except for one displaying problem I'm having (I will post it later). Good Luck.
kate damond
Ranch Hand

Joined: Apr 17, 2001
Posts: 77
I did something similar : the complex data stuff goes in the user Object for each node.
I find it useful to also keep a HashMap of nodes as they are created - useful for complete-match and partial match searching.
I agree. Here's the link:
subject: JTree question
It's not a secret anymore!