treemodel

Java: How to display an XML file in a JTree

佐手、 提交于 2019-11-26 20:46:43
问题 I would like to have a way to display the contents of an XML file in a JTree . I have already accomplished this using DOM, by implementing a custom TreeModel (and TreeCellRenderer ). However it is very clunky (much workaround-ery and hackery) and rather rough around the edges. Is anyone aware of a way to get a JTree to display the contents of an XML file, parsed with SAX? Thanks! 回答1: Here's the code that I use. It is based on the API of Dom4J, but you can easily convert it to the APIs of

Updating ImageIcon in JTree without repainting the Tree?

↘锁芯ラ 提交于 2019-11-26 14:55:05
问题 Basically I edit an attribute private string status="OK" in the UserObject() of a DefaultTreeNode() . I have a CustomRenderer which implements DefaultCellRenderer , which sets the Icon by rendering the "OK" attribute of UserObject of a TreeNode . Originally, when I select a node, the icon changes. I am using Tree.revalidate() & Tree.repaint() , and the change is being reflected. However, I am not sure if this very efficient. What would be the proper way of doing this? I tried doing TreeModel