Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   [JTree] click on a node or a leaf (http://www.velocityreviews.com/forums/t128522-jtree-click-on-a-node-or-a-leaf.html)

Alexandre Jaquet 11-10-2003 03:07 PM

[JTree] click on a node or a leaf
 
Hi I would like to know how know if a user click on a node or a leaf
thanks.



Thomas Weidenfeller 11-11-2003 07:57 AM

Re: [JTree] click on a node or a leaf
 
"Alexandre Jaquet" <alexj@freesurf.ch> writes:
> Hi I would like to know how know if a user click on a node or a leaf
> thanks.


You can ask the node if it is a leave or not. See the API documentation
of TreeNode.

/Thomas

Matthew Zimmer 11-11-2003 02:15 PM

Re: [JTree] click on a node or a leaf
 


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



All times are GMT. The time now is 01:56 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.