3

I've noticed that the jTree.treeModelHandler called & defined within jTree, implement blank methods for both treeNodesChanged & treeNodesInserted events. DefaultTreeModel fires a treeNodesInserted event & jTree updates itself. However, when I fire the same event from a TreeModel nothing happens.

I can't work out how the tree can update from DefaultTreeModel when it doesn't implement any apparent method to do so.

What am I missing here?

update: workaround org.jdesktop.swingx.tree.TreeModelSupport. Great bit of kit! Added as a field to my TreeModel interfaced object. Then delegated all firing & treeModelListener methods to it. Works better with JTree than DefaultTreeModel & even better with JXTree. I have only implemented singular selection/ insert / deletes but the tree has behaved correctly on all tests so far.

Simon Page
  • 69
  • 3
  • for better help sooner post an [SSCCE](http://sscce.org/) demonstrated a.m. issues, short, runnable, compilable, could be based on `Oracle` tutorial about `XxxTreeListener`, I think that question isn't answerable in this form – mKorbel Nov 16 '12 at 14:20
  • +1 for solving with TreeModelSupport (biased me :-) BTW: the tree treats all models the same and updates itself correctly, provided they fire the events correctly (which isn't trivial). The "main" listening is handled in the ui-delegate, the handler in the JTree itself is just a minor adjustment – kleopatra Nov 18 '12 at 17:31

1 Answers1

3

DefaultTreeModel does the firing itself. The listeners are on the model (so you can have two JTrees viewing the changes of one TreeModel). So the model is the correct spot to notify all listeners.

I believe one should try to extend the AbstractTreeModel as one then has some basic infrastructure. NOT TRUE


The TreeModel has TreeModelListeners too. For changes to the data. The JTree is such a listener. The JTree has listeners for the view aspects, whether branches got expanded and such.

In your TreeModel one has to walk all added TreeModelListeners and call the appropiate event like treeNodesInserted.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • 2
    Flameware == I can't see AbstractTreeModel based on Standard Oracle Apis, never ever , I think that question isn't answerable in this form – mKorbel Nov 16 '12 at 14:17
  • @Joop - Surely the listeners must be on the tree, if you had 2 trees then you would have 2 sets of listeners, one for each tree. – Simon Page Nov 16 '12 at 19:19