adding mouse listener to a tree
1 posts in topic
Flat View  Flat View

Posted By:   Ravishankar_CS
Posted On:   Wednesday, October 31, 2001 01:11 AM

I want to add a mouse listener to a tree
node i.e. when a tree node is right-clicked,I want to display a menu ox.
But i am unable to do it since I am getting an error saying that the addMouseListner method cannot be registered with a tree component.

so,can u please tell if i can call a mouselistener on a tree component and if so how to do it?

Re: adding mouse listener to a tree

Posted By:   Christopher_Brind  
Posted On:   Thursday, November 1, 2001 01:01 AM

The API docs give the following example of how to add and use a MouseListener with a JTree.

final JTree tree = ...;

MouseListener ml = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
if(selRow != -1) {
if(e.getClickCount() == 1) {
mySingleClick(selRow, selPath);
else if(e.getClickCount() == 2) {
myDoubleClick(selRow, selPath);

You may want to read the documentation for more information.
About | Sitemap | Contact