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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "generate Jtree" Watch "generate Jtree" New topic

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!


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

Joined: Feb 13, 2004
Posts: 244

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);
base.add(new DefaultMutableTreeNode(n1));


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 !

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.

I agree. Here's the link:
subject: generate Jtree
It's not a secret anymore!