treemodel

store state/expanded nodes of a jtree for restoring state

大憨熊 提交于 2019-12-07 01:31:01
问题 I am working with JTree. I would like to know what is best the way to know which nodes are expanded in a JTree so as to save its state (i.e. save all expanded paths). So that if I call model.reload() the Jtree would not stay collapsed, but I will be able to restore its original state to the user, i.e., all expanded nodes will be expanded. 回答1: Santhosh Kumar is one of my go-to guys for Swing Hacks. Answer: http://www.javalobby.org/java/forums/t19857.html 回答2: You need to store the TreePaths

expand Jtree at last modified area?

老子叫甜甜 提交于 2019-12-06 02:10:10
I am using dom4j to create a DocumentTreeModel from a dom4j document. I display this DocumentTreeModel inside JScrollPane . I have a button that adds a new node to the dom4j document, and recreates the DocumentTreeModel I am using getPathForRow but this seems pretty limited. I need to be able to work with multiple tree depth. Basically looking for something like tree.getPathOfLastModifiedChildrensParent() onAddNewNodeButtonClickEventFired { dom4jdocument.addElement( "1" ); tree.setModel(new DocumentTreeModel(dom4jdocument)); tree.expandPath(tree.getPathForRow(1)); } Basically I am trying to

Transforming a tree back to JSON using tree-model-js

心已入冬 提交于 2019-12-05 12:57:53
Is there perhaps a way in which you can convert a TreeModel to a JSON string. That way it can be stored and then later recreated using tree.parse() ? Currently when attempting JSON.stringify(root) it gives an obvious error about cyclic references (because children contain parents and parents contain children). Use JSON.stringify(root.model) instead. 来源: https://stackoverflow.com/questions/30193137/transforming-a-tree-back-to-json-using-tree-model-js

Cloning a JS TreeModel tree

女生的网名这么多〃 提交于 2019-12-05 06:11:07
I need to clone a tree I made using TreeModel.js . What I exactly need to do is duplicating it, make changes to it and check if the number of nodes decreased. If it did, revert to the original tree. Here's a small example of what I do so far to duplicate it, which is not correct: var tree = new TreeModel(); var root = tree.parse({ id: 0, name: "Root", children: [{id: 1, name: "1", children: []},{id: 2, name: "2", children: []}] }); console.log(root) var dup = tree.parse(root) console.log(dup) Here's a Fiddle . You'll see the difference between the trees by looking at the console: Node {config:

store state/expanded nodes of a jtree for restoring state

只谈情不闲聊 提交于 2019-12-05 04:36:36
I am working with JTree. I would like to know what is best the way to know which nodes are expanded in a JTree so as to save its state (i.e. save all expanded paths). So that if I call model.reload() the Jtree would not stay collapsed, but I will be able to restore its original state to the user, i.e., all expanded nodes will be expanded. Santhosh Kumar is one of my go-to guys for Swing Hacks. Answer: http://www.javalobby.org/java/forums/t19857.html Thomas Ziegenhein You need to store the TreePaths that were expanded and expand them again after reloading the TreeModel. All TreePaths that have

Adding and removing nodes from a JTree

若如初见. 提交于 2019-12-04 16:45:24
问题 I have a very basic JTree . As I am on a rush, I'd prefer not to use TreeModel if it is not needed. I wrote a SSCCE to expose the problem: Sometimes I add a node. Other times I remove them. When I push Add , a node is correctly added. When I push Remove , it is supposed to remove the node, but it doesn't. Also, if I try adding more than one node, the tree stays with just the first node I added. I wrote an update method for the JTree , where I first erase all the nodes hanging from the root

Adding and removing nodes from a JTree

徘徊边缘 提交于 2019-12-03 09:51:23
I have a very basic JTree . As I am on a rush, I'd prefer not to use TreeModel if it is not needed. I wrote a SSCCE to expose the problem: Sometimes I add a node. Other times I remove them. When I push Add , a node is correctly added. When I push Remove , it is supposed to remove the node, but it doesn't. Also, if I try adding more than one node, the tree stays with just the first node I added. I wrote an update method for the JTree , where I first erase all the nodes hanging from the root node, and then I look at which nodes and sub-nodes I have to create. What I am doing wrong here, apart

TreeModel creation

非 Y 不嫁゛ 提交于 2019-12-02 09:58:52
I have some questions regarding a treemodel in Java. For the last 13 weeks in class we've been developing a contact manager. This contact manager has various components: a contact can either be a business contact or personal contact, and each has their own set of events. They also have addresses, social networks, and phone numbers. Last assignment we had to read information from an outside txt file and implement it in our project. That went fine. Now he wants us to build a treeModel out of the information from said text, but I'm having a really hard time understanding how this tree model works

Java: How to display an XML file in a JTree

心不动则不痛 提交于 2019-11-27 21:42:08
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! 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 your favorite XML library: public JTree build(String pathToXml) throws Exception { SAXReader reader = new

Updating ImageIcon in JTree without repainting the Tree?

折月煮酒 提交于 2019-11-27 09:51:32
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.nodesChanged(new DefaultMutableTreeNode(myUserObject)) but the TreeNodeChanged event will not fire. So