Hi,
I have implement a JTree in my code. I have also added a TreeSelectionListener to this and written code for valueChanged(TreeEvent e). If the user selects a node then the valueChanged method displays information relating to that node.
I now wish to let the user type in the name of the leaf they are looking for and display the leaf in the tree and the information pertaining to it.
I have used the following code:
mtm.collapseTree();
response = null;
response = JOptionPane.showInputDialog(null,
"Enter MIBNode name or Object Identifier",
"Find a MIBNode",
JOptionPane.PLAIN_MESSAGE);
DefaultMutableTreeNode node = MibTreeModel.getModel().getNode(response);
if(node != null) {
TreePath path = new TreePath(node.getPath());
mtm.expandPath(path);
mtm.setSelectionPath(path);
mtm.scrollPathToVisible(path);
mtm is the JTree object and response is a String.
When I run my program it does as its meant to for the first couple of leaf names I type in. However, after a couple of attempts, when I type in anything the tree remains collapsed and no information is being displayed.
Why is this happening ??
What happens if I have more than one leaf with the same name ??
Thanks,
Tom
I have implement a JTree in my code. I have also added a TreeSelectionListener to this and written code for valueChanged(TreeEvent e). If the user selects a node then the valueChanged method displays information relating to that node.
I now wish to let the user type in the name of the leaf they are looking for and display the leaf in the tree and the information pertaining to it.
I have used the following code:
mtm.collapseTree();
response = null;
response = JOptionPane.showInputDialog(null,
"Enter MIBNode name or Object Identifier",
"Find a MIBNode",
JOptionPane.PLAIN_MESSAGE);
DefaultMutableTreeNode node = MibTreeModel.getModel().getNode(response);
if(node != null) {
TreePath path = new TreePath(node.getPath());
mtm.expandPath(path);
mtm.setSelectionPath(path);
mtm.scrollPathToVisible(path);
mtm is the JTree object and response is a String.
When I run my program it does as its meant to for the first couple of leaf names I type in. However, after a couple of attempts, when I type in anything the tree remains collapsed and no information is being displayed.
Why is this happening ??
What happens if I have more than one leaf with the same name ??
Thanks,
Tom