I have a JTree with a few nodes and subnodes. When I click on a node I want to know on which depth is it (0, 1, 3). How can I know that?
selected_node.getDepth();
doesn’t return the depth of current node..
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should be using
getLevel.getLevelreturns the number of levels above this node — the distance from the root to this node. If this node is the root, returns 0. Alternatively, if for whatever reason you have obtained theTreenode[]path (usinggetPath()) then it is sufficient to take the length of that array.getDepthis different, as it returns the depth of the tree rooted at this node. Which is not what you want.