Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Select a node in Jtree

 
Swetha Krish
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a text box and when the user enters the value and click the "Search Button", the value needs to be searched in the Jtree and need to highlight the node.






If I enter the string and hit search , I am able to search the tree and get the exact node and its path.

But I could not make it selected. If the node is collapsed I need to expand and select it.

Path count is 3.

Can anyone help in getting this done.
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please try the below bit of code....

 
Swetha Krish
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the code and still the given node is not selected.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once again I must be missing something. Your code

creates a brand new JTree that has nothing to do with the JTree that is displaying your TreeModel. I would expect you to use the JTree that is currently displaying the TreeModel.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch Swetha Krish
 
Swetha Krish
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it.I worked...Thank you....
 
Swetha Krish
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to return all the possible nodes matching the search string and make them selected.
 
Paul Clapham
Sheriff
Pie
Posts: 20715
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see why not. Of course you would have to change the tree's selection model to allow multiple selections, but beyond that it's probably a very simple change to your existing code.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Continued here: http://www.coderanch.com/t/544262/GUI/java/Help-needed-selecting-multiple-nodes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic