JTree set handle visible on first node level when root is not displayed
I have a JTree like this:
MasterRoot
+-RootA
+-ChildA1
+-GrandChildA1a
+-RootB
+-ChildB1
+-GrandChildB1a
I don't want the MasterRoot node to be displayed But if I call `configTree.setRootVisible(false);
I got:
RootA
+-ChildA1
+-GrandChildA1a
RootB
+-ChildB1
+-GrandChildB1a开发者_JAVA百科
And I want this:
+-RootA
+-ChildA1
+-GrandChildA1a
+-RootB
+-ChildB1
+-GrandChildB1a
Note: yes I just need the '+-' (what the name for that ? Node Handler ??) to be displayed to my first level nodes after the master root.
The '+-' is called a 'handle' and the method you need to call is setShowsRootHandles(true)
.
This is really just a hint to the UI. It's left up to the look and feel whether to honor the hint.
精彩评论