Adding an action listener for a node in a tree

I cannot add an action listener to a specific node in the tree. This is the tree I built:

enter image description here

I want to register a separate listener for each node. Now I registered the listener on JTree . therefore, whenever I click on any part of the tree , the listener method starts to work. (I now have a regular listener) What I want is when I click on an audio listener registered to listen to an audio click, it should start its work and the same for video. How can i do this?

Here's how I registered so far:

 jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { jTree1ValueChanged(evt); } }); public void jTree1ValueChanged( TreeSelectionEvent tse ) {...} 
+4
source share
2 answers

How about this one. Or do you have special PathComponents?

 public void jTree1ValueChanged( TreeSelectionEvent tse ) { String node = tse.getNewLeadSelectionPath().getLastPathComponent().toString(); if( node.equals("audio") ) { // play audio } else if( node.equals("video") ) { // play video } } 
+7
source

You cannot add an event listener to tree-node because the class representing the node tree is not a Component.

0
source

All Articles