how to convert dom4j xml into Swing Jtree?
I am using dom4j to parse xml. Then I want to be able to represent this xml as a Jtree. Whenever I programmatically add or remove nodes through dom4j, I want the changes to be reflected immediately in the Jtree. When I click on a Jtree node, how do I catch the event?
I've discovered the dom4j.swing package at http://dom4j.sourceforge.net/apidocs/
However, I don't know how I would go about using that. Which I should use, I am not sure. I can't seem to find any examples or tutorials on this area.
BranchTreeNode, 开发者_如何转开发DocumentTreeModel, LeafTreeNode.
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
public class Foo {
public Document createDocument() {
Document document = DocumentHelper.createDocument();
Element root = document.addElement( "root" );
Element author1 = root.addElement( "author" )
.addAttribute( "name", "James" )
.addAttribute( "location", "UK" )
.addText( "James Strachan" );
Element author2 = root.addElement( "author" )
.addAttribute( "name", "Bob" )
.addAttribute( "location", "US" )
.addText( "Bob McWhirter" );
return document;
}
}
See http://www.docjar.com/docs/api/org/dom4j/samples/swing/JTreeDemo.html, is this what you're looking for?
精彩评论