JTree event listener on root node problem

Posted on 2005-04-09
Last Modified: 2008-02-01
I have a JTree to let the user build folders and items (nodes) interactively. This is done by rightclicking an existing node, a listener then opens a popup with some options... The problem is that I cannot show a popup menu when the user clicks on the ROOT node (wich seems to be default in a JTree). The listener isn't even activated when one clicks the ROOT.

I have a listener attached to the JTree:

tree.addTreeSelectionListener(new TreeSelListener());         //when node is selected
tree.addMouseListener(new PopupMenuListener());              //when tree is clicked

Following class is always triggered when a node is clicked, except for the ROOT node :

private class TreeSelListener implements TreeSelectionListener

Any ideas on this one?
Question by:Droezel
    LVL 92

    Accepted Solution

    What exactly isn't firing
    If the selection doesn't changed the the selection listener won't fire.
    And right clicking doesn't actually select a node from memory, you would need to select the appropriate node in your mouse listener when the node is right clicked.
    LVL 92

    Assisted Solution


    Author Comment

    Thanks, the problem is solved. My question wasn't clear enough, but your answers assisted in solving it...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now