![]() |
[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. |
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 |
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 06:15 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.