Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generate Jtree

 
Moniphal Say
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic