1

So far I have used dom4j's DefaultTreeModel to create a Jtree out of the xml file it reads.

The problem is that the Jtree doesn't refresh everytime the xml is changed, or a node is added or removed.

So far, it appears there is much plumbing code involved because there doesn't seem to be implementation of OnXmlChanged().

What other alternatives do I have of incorporating a visual tree xml swing component that also supports event firing upon change in the underlying xml file.

KJW
  • 15,035
  • 47
  • 137
  • 243

1 Answers1

2

You can always fire these events your self when you know that something has changed, From DefaultTreeModel, use:

protected  void fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children) 

protected  void fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children) 

protected  void fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children) 

protected  void fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children) 
MeBigFatGuy
  • 28,272
  • 7
  • 61
  • 66
  • +1 See also [this alternative](http://stackoverflow.com/questions/5664041/java-treetable-problem/5664525#5664525). – trashgod Apr 25 '11 at 00:05
  • sure, it's possible - just ton's of work and not exactly reliable: the document might change under the feet of the both the model and any "agent" related to it. Couldn't find any obvious (low-workload) solution: http://stackoverflow.com/questions/5579580/expand-jtree-at-last-modified-area – kleopatra Apr 26 '11 at 12:03