Reputation: 124
I'm writing a MouseListener
to replace the default clicking behaviour in the JTree
. How can I tell when this icon is clicked so I can expand the row myself? (I know this is default behaviour, but I'm replacing the default MouseListener
with my own MouseListener
).
Here's my code:
// Custom mouse listener for the tree
MouseListener treeMouseListener = new MouseAdapter()
{
public void mousePressed (MouseEvent e)
{
TreePath path = cameraTree.getPathForLocation(e.getX(), e.getY());
// Do some methods based on what was clicked
...
}
};
The TreePath returned by cameraTree.getPathForLocation(e.getX(), e.getY())
is null when clicking on the +/- icon. How can I tell when that +/- icon is clicked?
Upvotes: 0
Views: 945
Reputation: 91
If you are using JTree, you could use a TreeSelectionListener. More info here: http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html
Upvotes: 1