开发者

Creating JTree using parsed XML document

开发者 https://www.devze.com 2023-01-19 11:06 出处:网络
i want to create a JTree resembling XML dom in java.. below is the XML form... <html> <head>

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

精彩评论

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