Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree question

 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
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, MyEffect.name to label the node?
any advice would be gratefully received.
cheers,
Ben.
 
Sonny Pondrom
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Kate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic