dom4jを使用してxmlを解析しています。次に、このxmlをJtreeとして表現できるようにします。プログラムでdom4jを介してノードを追加または削除するときはいつでも、変更がJtreeにすぐに反映されるようにします。Jtreeノードをクリックすると、イベントをキャッチするにはどうすればよいですか?
私はhttp://dom4j.sourceforge.net/apidocs/でdom4j.swingパッケージを発見しました
しかし、それをどうやって使うのかわかりません。どちらを使うべきかわかりません。この領域の例やチュートリアルが見つからないようです。
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;
}
}