Hi,
I have implemented a JTree.
The tree can be expanded by clicking the handles beside the nodes and when the nodes are clicked on, any information pertaining to that node is displayed. I have also implemented a search function for the tree, which allows the user to click a button and a dialog appears. The user can enter the name of the node they are looking for and the tree expands to show the node and the information is displayed.
However I have found that if I use the search function on a node in the tree and then use click method to find the same node, and finally try and use the search method again the tree fails to expand on the last attempt.
I have traced this problem down to a HashMap but am unable to figure out why the problem is occurring. When the table is being built I have a method that is used to build the tree:
DefaultMutableTreeNode child = node;
child = new DefaultMutableTreeNode(Node);
HashMap.put(Node, child);
node.add(child);
Each node is added to the tree successfully. When I initiate my search function the following is called:
DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) HashMap.get(Node);
Debugging this reveals that it works perfectly for each Node item until I use the click method. When I click on a node another method is called which gets the location of the click and returns the TreePath to the node. This method works perfectly and always displays the information. Naturally the tree is expanded as the user has to expand the tree to selected the node.
Now when I use the search method again, and look for the same Node, or a Node within the table, I find that the code
DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) HashMap.get(Node);
returns a null.
Why is this ??
Why is the key, the Node, present while I use the search method but once the click method is used, does this key no longer exist in the HashMap.
Thanks for your help
I have implemented a JTree.
The tree can be expanded by clicking the handles beside the nodes and when the nodes are clicked on, any information pertaining to that node is displayed. I have also implemented a search function for the tree, which allows the user to click a button and a dialog appears. The user can enter the name of the node they are looking for and the tree expands to show the node and the information is displayed.
However I have found that if I use the search function on a node in the tree and then use click method to find the same node, and finally try and use the search method again the tree fails to expand on the last attempt.
I have traced this problem down to a HashMap but am unable to figure out why the problem is occurring. When the table is being built I have a method that is used to build the tree:
DefaultMutableTreeNode child = node;
child = new DefaultMutableTreeNode(Node);
HashMap.put(Node, child);
node.add(child);
Each node is added to the tree successfully. When I initiate my search function the following is called:
DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) HashMap.get(Node);
Debugging this reveals that it works perfectly for each Node item until I use the click method. When I click on a node another method is called which gets the location of the click and returns the TreePath to the node. This method works perfectly and always displays the information. Naturally the tree is expanded as the user has to expand the tree to selected the node.
Now when I use the search method again, and look for the same Node, or a Node within the table, I find that the code
DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) HashMap.get(Node);
returns a null.
Why is this ??
Why is the key, the Node, present while I use the search method but once the click method is used, does this key no longer exist in the HashMap.
Thanks for your help