File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes generate Jtree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "generate Jtree" Watch "generate Jtree" New topic
Author

generate Jtree

Moniphal Say
Ranch Hand

Joined: Aug 11, 2004
Posts: 48
Hi all,

I have one file .dtd, I want to generate Jtree (show the content of the file inform of Jtree).
Anyone could tell me how to do it please!

Moniphal


<b>The more we learn, the more we know !</b>
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hello,

Jtree is a Swing component. Anyways use the following code snippet.

DefaultMutableTreeNode root;
root = new DefaultMutableTreeNode("Foods");
JTree tree = new JTree(root); //create tree
addNodes(<elments of the xml file after parsing> ;

private void addNodes(String b, String n1)
{ DefaultMutableTreeNode base = new DefaultMutableTreeNode(b);
root.add(base);
base.add(new DefaultMutableTreeNode(n1));
}

Rgds,

Seetesh
Moniphal Say
Ranch Hand

Joined: Aug 11, 2004
Posts: 48
Dear Seetesh,

Thanks so much for your help !
I will back to ask questions again if I have any problems !

Regards,
Moniphal
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
I was just wondering the same thing. A DTD isn't xml though, Are there any good apis for parsing DTDs (is this part xalan xerces or some other common tool)?

Is there an elegant way to extend a J-tree to show the relationships between parent and nested tags ? optional, + one or more, * 0 or many. etc. The Jtree can nicely show order and what is allowed but seems to fall a little short in showing the relationships I mentioned.

-Tad
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: generate Jtree