简体   繁体   English

重写JTree双击以防止节点扩展?

[英]overriding JTree double-click to prevent node expansion?

It looks like there are 2 default mechanisms to expand a folder node in a JTree. 看起来有两种默认机制来扩展JTree中的文件夹节点。 One is to click on the expanded/collapsed icon next to a node. 一种是单击节点旁边的展开/折叠图标。 The other way is to double-click on the node itself. 另一种方法是双击节点本身。

Is there a way to stop this 2nd mechanism? 有没有办法阻止这第二种机制? I would like to override the double-click on a node so it does something (updates another display to show statistics on the node being double-clicked), and would like it to not expand/collapse the tree node. 我想覆盖节点上的双击,以便它做某事(更新另一个显示以显示双击节点的统计信息),并希望它展开/折叠树节点。 (just to be clear: I don't want to prevent the node from being expanded/collapsed, I just want to require the user to click on the expanded/collapsed icon.) How can I do this? (只是要明确:我不想阻止节点扩展/折叠,我只是想要求用户点击展开/折叠图标。)我该怎么做?

From the relevant API page , you would do something like this: 在相关的API页面中 ,您可以执行以下操作:

JTree tree = new JTree();
tree.setToggleClickCount(0);

This means you must use 0 clicks to expand a tree node, effectively disabling double click. 这意味着您必须使用0次单击才能展开树节点,从而有效地禁用双击。 This will not interfere with other methods of tree expansion. 这不会干扰其他树扩展方法。

Call setToggleClickCount(0) on the JTree 在JTree上调用setToggleClickCount(0)

This will effectively disable expanding on double-click. 这将有效禁用双击扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM