0

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;
    }
}
4

1 に答える 1

1

http://www.docjar.com/docs/api/org/dom4j/samples/swing/JTreeDemo.htmlを参照してください。これはあなたが探しているものですか?

于 2011-04-01T07:08:54.267 に答える