I have a JTree structure as shown below. I have Icons that appear whenever a node has child nodes, which is working properly.

My problem is that I need to hide the ROOT node. When I hide the ROOT node, the Icons for MainTop1 and MainTop2 nodes are not displayed, even though they have children. To hide ROOT node I'm using "setRootVisible(false)".

Also when ROOT node is hidden, the Icons for Topic1 and Topic nodes are displayed properly.

Anyone knows how to display the Icons for MainTop1 and MainTop2 when ROOT is hidden? Thanks in advance.

Below is my tree structure:

ROOT
    MainTop1
        Topic1
            Subtopic1
            Subtopic2
    MainTop2
        Topic2
            Subtopic1
有帮助吗?

解决方案

JTree#setShowsRootHandles(boolean newValue) controls the state of the handles for root elements.

Normally, this is false. Try changing to true

其他提示

The order of the factors affects the product:

  1. Create all nodes
  2. Create model
  3. Add nodes to model
  4. Create JTree
  5. setRootVisible(false)
  6. setModel()

simple example

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top