Reputation: 23226
I am unable to add action listener to a particular node in the tree. This is a tree that i've constructed :
I want to register a separate listener for each node . Now i have registered a listener on JTree
. so, whenever i click on any portion of tree
the listener method starts it's work. (i.e now i have a common listener )
What i want is when i click on audio a listener registered to hear audio click, should start it's work and the same goes for video. How can i do that ?
This is how i have 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 ) {...}
Upvotes: 4
Views: 14596
Reputation: 3870
You cannot add an event listener to tree-node because the class representing the tree-node is not a Component.
Upvotes: 0
Reputation: 7507
What about this. 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
}
}
Upvotes: 7