简体   繁体   English

有没有办法在JTree中有多个根的扩展器图标?

[英]Is there a way to have expander icons for multiple roots in a JTree?

I have a JTree with multiple "roots" (Of course, I actually have an invisible real root with multiple children). 我有一个具有多个“根”的JTree(当然,我实际上有一个有多个孩子的隐形真根)。

The nodes expand and collapse on double click, but there's no visual indication that you can do this as there is no expander icon. 双击时节点会展开和折叠,但由于没有展开器图标,因此没有可视指示可以执行此操作。

This is made worse by the fact that the tree is collapsed by default, but expanding the "roots" doesn't really help, as each has many children and it would look cluttered. 由于默认情况下树被折叠这一事实使情况变得更糟,但扩展“根”并没有真正帮助,因为每个人都有很多孩子并且它看起来很杂乱。

Is there a way to display the expander icons without making the real (and utterly valueless) root visible? 有没有办法显示扩展器图标而不会使真实(并且完全没价值)的根可见?

Any other suggestions to make the display clearer welcome. 任何其他建议,以使显示更清晰的欢迎。

Would tree.setShowsRootHandles(true) be a good way to display those "expander icons" ? tree.setShowsRootHandles(true)显示那些“扩展器图标”吗?

A tree typically also performs some look-and-feel-specific painting to indicate relationships between nodes. 树通常还执行一些特定于外观的绘画以指示节点之间的关系。 You can customize this painting in a limited way. 您可以以有限的方式自定义此绘画。

  • First, you can use tree.setRootVisible(true) to show the root node or tree.setRootVisible(false) to hide it. 首先,您可以使用tree.setRootVisible(true)来显示根节点,或使用tree.setRootVisible(false)来隐藏它。
  • Second, you can use tree.setShowsRootHandles(true) to request that a tree's top-level nodes — the root node (if it is visible) or its children (if not) — have handles that let them be expanded or collapsed . 其次,您可以使用tree.setShowsRootHandles(true)来请求树的顶级节点 - 根节点(如果它是可见的)或其子节点(如果没有) - 具有允许它们展开或折叠的句柄

Check also your look and feel to be sure what the renderer does with your tree. 还要检查您的外观,确保渲染器对您的树有什么作用。

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

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