Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for an item in a JTree (Urgent)

Status
Not open for further replies.

tlohan

Programmer
Sep 14, 2001
19
BE
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top