I am using a CheckBoxTree and want to detect clicks on the items in it. To this end, I created a MouseListener which I added to my CheckBoxTree.
In my mouselistener I do the following to get the TreePath that is clicked:
- Code: Select all
public void mousePressed( MouseEvent e )
{
if ( e.getComponent() instanceof CheckBoxTree )
{
CheckBoxTree tree = (CheckBoxTree)e.getComponent();
TreePath path = tree.getPathForLocation( e.getX(), e.getY() );
}
}
Now, I only want to do something when the label of the path is clicked, not the checkbox. I cannot figure out how to check this. I tried calling getComponentAt(x,y) several times on the tree (as each call only goes 1 level deep), but this keeps returning the CheckBoxTree.
Any ideas?