开发者

Creating JTree using parsed XML document

i want to create a JTree resembling XML dom in java.. below is the XML form...

<html>
  <head>
    <title></title>
    <style></style>
    <body></body>
  </head> 
  <head>
    <title></title>
    <style></style>
    <body></body>
  </head>
</html> 

i want to create thi开发者_StackOverflow中文版s tree structure....


You can do it easily by parsing the XML and creating a DefaultMutableTreeNode for each XML element. Tree nodes have parents and children just like XML elements so the mapping is easy.

If you set the Element as the user object in DefaultMutableTreeNode you will probably want to provide a custom TreeCellRenderer.


There is a full example here: http://www.cafeconleche.org/books/xmljava/chapters/ch06s05.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜