Solved

Java jTree -> getting parent node

Posted on 2007-03-21
5
279 Views
Last Modified: 2012-06-27
I need to get the parent node when highlighting a child node:

node 1
---node1.1
---node1.2
---node1.3
---node1.4
node 2
---node2.1
---node2.2

So if I highlight node 2.2....
I can get that string by :

String node = jt.getSelectionPath().getLastPathComponent().toString();

But the question is... how do I get it's parent node as a String.... highlighting the child?

String parentNode = ?
0
Comment
Question by:RicardoVGomes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 18767841
String parent = jt.getSelectionPath().getPathComponent(0).toString();
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 18767856
What does

System.out.println(jt.getSelectionPath().getLastPathComponent());

give you?
0
 

Author Comment

by:RicardoVGomes
ID: 18767968
String parent = jt.getSelectionPath().getPathComponent(0).toString();

always gives me the same String.... parent node 1.... its suppose to give me the parent node for any child node..... so for node 2.2 ... i want node 2..... node 4.8 ... i want node 4.

------------------------------

System.out.println(jt.getSelectionPath().getLastPathComponent());

gives me the highlighted node.



0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 18767991
sorry missunderstodd, then just go one level up in path

String parent = jt.getSelectionPath().getParentPath().getLastPathComponent().toString();
0
 

Author Comment

by:RicardoVGomes
ID: 18768003
Thats it.

Thanks
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question