Alexandre Jaquet wrote:
> Hi I would like to know how know if a user click on a node or a leaf
> thanks.
>
>
Do you mean how to know when something is selected or if the something
selected is a node or not? If you mean the first, use this:
myTree.addTreeSelectionListener(new TreeSelectionListener()
{
public void valueChanged(TreeSelectionEvent evt)
{
TreePath path = this.getSelectionPath();
if (path != null)
{
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)path.getLastPathComponent( );
if (node.isLeaf())
{
// do child stuff
}
else
{
// do parent stuff
}
}
}
});
Hope that helps.
Matthew
|