• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sharing JTree access  RSS feed

 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a JTree and need to allow it to be seen on two tabbed panes. However I also allow nodes to be added and deleted via one of the tabbed panes and this must be shown in the other. If I move the JTree code into a seperate class how can I get the two tabbedpane classes to use it? I.e. they must be using the same object.
Thanks
Amy
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hy Amy,
I guess you have a small problem.
The JTree - class is a tight couple of a Collection, and it's graphical representation.
There is no easy way to build two graphical representations from the same data.
Perhaps you can isolate the data, and build two JTreeS. Then you have to take care in keeping those two trees in sync with your data (insert, update, modify, delete, movement).
A tricky job, though possible.
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears to fit nicely into the MVC model. The model, your data, is sharable among the views, your two jtree tables. By implementing callback method in the views, when data in one view is modified, the other view will be updated via the callback method
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for your responses,
I think I am making some progress (although slowly):
The data for the trees is stored in an arraylist and updated to show changes to the data. The tree then accesses this arraylist to build itself.
I have seperated the Jtree into a seperate class and want the two tabbedpanels to access this class to display the tree. However I am getting a little confused. Does the JTree class need to be abstract? and how do I point the two panes towards the tree? i..e do they extend the tree or what?
Thanks very much
Amy
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amy Phillips:
I have seperated the Jtree into a seperate class and want the two tabbedpanels to access this class to display the tree. However I am getting a little confused. Does the JTree class need to be abstract? and how do I point the two panes towards the tree? i..e do they extend the tree or what?
Amy


Hi Amy,
I think the guys are saying that your arrayList should go into a DefaultTreeModel instance, and that instance should be used to construct two JTree instances, each of which will go into a separate panel. Both JTree instances will fire changes into the model which fires them back to the other JTree instance.
You could also make your own tree model implementing TreeModel but I think that would be a lot of tricky work. I don't think the tree people have an AbstractTreeModel taking care of everything bar the storage as do the table people with their AbstractTableModel.
[ March 28, 2004: Message edited by: Eddie Vanda ]
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks very much you three. I have finally got it working with elements of the MVC to update the two views when changes are made. I expect I can optimise it somewhat but for now I am just glad to have the functionality so maybe I'll return with more questions later!
Thanks a lot
Amy
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!