有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java有没有办法在JTree中为多个根使用扩展图标?

我有一个具有多个“根”的JTree(当然,我实际上有一个具有多个子元素的隐形实根)

双击时节点会展开和折叠,但没有可视指示可以这样做,因为没有展开图标

更糟糕的是,树在默认情况下是折叠的,但是扩展“根”并没有真正的帮助,因为每个树都有很多子树,看起来很杂乱

有没有一种方法可以显示扩展器图标,而不使真实的(完全没有价值的)根可见

欢迎您提出其他建议,使显示更清晰


共 (1) 个答案

  1. # 1 楼答案

    {a1}会是{a2}那些“扩展图标”吗

    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.
    • 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.

    还要检查look and feel以确保渲染器对树执行的操作