3

I'm trying to customize a JTree so that I can use it in a project that I'm working on. That project GUI's style does not fit the default Java LNF's node handles for JTree which is why I tried to replace them with custom-made icons but I'm stuck as to how I can do that. I don't know if that helps but I already have an own LNF class which loads the default LNF settings and overrides some of them with custom values.

Alternatively, if replacing the handles' icons is too complex to explain it in an answer here, how can I completely disable them so that I can use custom open/closed icons for all expandable nodes?

mezzodrinker
  • 998
  • 10
  • 28
  • 2
    Try having a look at the `UIManager ` properties `Tree.collapsedIcon` and `Tree.expandedIcon`. There's also `Tree.closeIcon` and `Tree.openIcon` but I think they relate to the node icons, not the branches. Something like `UIManager.put("Tree.collapsedIcon", icon);`. You might want to use `UIManager.getIcon(...)` to test what the values are currently, but I think the basic idea should work – MadProgrammer Oct 31 '15 at 22:26
  • 2
    Which is also demonstrated [here](http://stackoverflow.com/questions/14260185/customizing-tree-collapsedicon-for-a-single-jtree) – MadProgrammer Oct 31 '15 at 22:28
  • @MadProgrammer I'll try that out right now. – mezzodrinker Oct 31 '15 at 22:28
  • @MadProgrammer Thanks, setting `Tree.collapsedIcon` and `Tree.expandedIcon` worked out just fine! The other two are indeed for setting the node icons. I wonder how I could overlook those two properties... – mezzodrinker Oct 31 '15 at 22:35
  • 1
    @MadProgrammer I know you don't need the reputation but would you please write an answer anyway? Just for the sake of completeness. – mezzodrinker Oct 31 '15 at 22:37
  • You can [answer your own question](http://meta.stackoverflow.com/q/17463/163188), citing @MadProgrammer's [comment](http://stackoverflow.com/questions/33457183/replace-jtree-handle-icons#comment54701069_33457183) . – trashgod Nov 01 '15 at 03:09
  • @trashgod Yeah, I know but... Oh well. If he's not going to do this, I might as well answer my own question. – mezzodrinker Nov 01 '15 at 04:53

1 Answers1

1

By setting the UIManager properties Tree.collapsedIcon (for collapsed handles) and Tree.expandedIcon (for expanded handles) to the desired values, the handles for all JTrees can be changed at once. Thanks to @MadProgrammer for suggesting the examples shown here, here, here and here.

Community
  • 1
  • 1
mezzodrinker
  • 998
  • 10
  • 28