Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using TreeModel: How to implement editing!!??  RSS feed

 
raphael Bereh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am implementing TreeModel to buil a custom model to a JTree.
My problem is when a Edit the Model (add,remove,change value of a Node ) my Tree does no refresh to present the accurate data. I have seen lots of example on the web, but each time people are using DefaultMutableTree .. to perform editing operation. I am writing an xml Editor that uses a DOM parser to read the data into a DOM that I display using a JTree. Then I sue a SAX 2 parser to validate the data against a schema and display errors in a different rendering. Now I need to enable the user to edit the xml DOM Tree in order to correct the file.
Itried implementing a TreeModelListener class, but I have no idea of what kind of code should go into each method of the interface to get my tree updated.
I really need help quicklly and would be greatefull of example with code samples:I read a lot about the theory but still not getting there
Thanks.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Swing.
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use any of the methods in DefaultTreeModel that work best for you:
nodeChanged(TreeNode node)
nodesChanged(TreeNode node, int[] childIndices)
nodeStructureChanged(TreeNode node)
nodesWereInserted(TreeNode node, int[] childIndices)
nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren)
fireTreeNodesChanged(Object source, Object[] path,
int[] childIndices, Object[] children)
fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children)
fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children)
fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children)
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!