Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting path with Tree Listener  RSS feed

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I'm just starting to work with trees. I have a JTree created, now I want to take the path that the user has selected, and return it to my app. For example, The user may have expanded the node "Showcases", then expanded "1/3 Vision", then clicked on "With Doors". I want to be able to return a value as three strings...
"Showcases" "1/3 Vision" "With Doors" to my app to place into three different text fields.
I've looked at a couple of examples, but they didn't seem to do what I want to.
Can someone help me out a little?
Thanks!
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thought I'd post what code I have out here. I know I'm doing something wrong, but not sure what it is... Notes in the code tell where problems are that I know of...


Thanks for any help!
 
raj madhuram
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for the "// Keep getting an ArrayIndexOutOfBounds Exception here...", replace "<=" with "<". Need more info on your other problem.
Regards,
Raj
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that. When I change the operator to "<", the code in the for loop does not run??
Any other ideas?
Also, I believe the ArrayIndexOutOfBounds exception is occurring when I try to set the parameters for my stored procedure (line 1 of the for loop).
[ April 08, 2003: Message edited by: Jennifer Sohl ]
 
raj madhuram
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you aware that tree.getSelectionPaths() returns all selected paths? Since I believe you had selected a single node, the loop doesn't run (because length is 1).
If you have single selection and want to retrieve the individual path components, this is the way to do:

Also, you may want to determine if the node is a leaf node before doing this.
Regards,
Raj
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj,
I was just about to post back. After taking another look at my code, I realized that I was doing a getSelectionPaths() vs. getSelectionPath(). This solved my ArrayIndexOutOfBounds problem. You are right on the money!
However, I am still having the problem with the cursor state not being valid.
When I select a node on the tree, I am going back out to the database (DB2/400) to get the ID for the description chosen. The stored procedure runs 3 select statements and returns 3 result sets. The first result set processes OK, however when I do the "getMoreResults()" in my code, it returns the SQLException Cursor state not valid.
Any ideas?
Thanks again!
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wanted to post back and let you know, I found my problem with my Cursor State Not Valid error.
In my code where I put

I forgot to add the following line of code before
looping through my result set...

Works beautifully now.
Thanks for all of your help!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!