Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:23:46+00:00 2026-06-15T05:23:46+00:00

I have tree with several nodes and also create one tree listener for that,now

  • 0

I have tree with several nodes and also create one tree listener for that,now i need to get the specific node path when it is clicked,
I have tried this code but didn’t get exact output can anybody help me?

public class FTListener implements TreeSelectionListener {


    @Override
    public void valueChanged(TreeSelectionEvent e) {
        TreePath[] tree=new TreePath[e.getNewLeadSelectionPath().getPathCount()];
        int i=0;

        tree=e.getPaths();

        for(TreePath tr:tree){
            System.out.println(tree[i]);
        i++;}

        //getPath() returns the array elements so i'm here using 
    //for loop for printing each elements.

this is the output

[/Desktop, /home/user/Desktop, /home/user/Desktop/1302677132563_USER_MANUAL_SMS_BANKING.pdf]
[/Desktop, /home/user/Desktop, /home/user/Desktop/Lab090C .java~]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:23:47+00:00Added an answer on June 15, 2026 at 5:23 am

    Do this

    public void valueChanged(TreeSelectionEvent e) {
    
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)
                           tree.getLastSelectedPathComponent();
    
        if (node == null) {
        //since Nothing is selected.     
         return;
        }
    
        Object nodeObject = node.getUserObject();
        System.out.println("Selected node : " + nodeObject);
    }
    

    Add this if you want only single selection

    tree.getSelectionModel().setSelectionMode
            (TreeSelectionModel.SINGLE_TREE_SELECTION);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have several, separately editable cells for a tree node. A TreeTable
I am using jstree and several nodes in my tree have the same name.
So, what we need to implement is a tree-menu with several nodes (up to
I have several threads. And I'd like to create sub-threads in one of them.
I have a tree that consists of several objects, where each object has a
I have a web app that has several tree views. When the page loads
I have a JSF application with several major components and a component tree under
I have a tree(jstree) inside a div, so when a node gets expanded the
I have a tree table with two columns on a page. The first one
I have a tree structure where each Node has a parent and a Set<Node>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.