Skip to main content

JXtreeTable custom icons per node

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
permeable
Offline
Joined: 2010-11-10

I would like to have custom icons for the tree nodes, depending upon the node's userObject field. I have looked through the forums and not seen an answer.
How do I set the open/close/leaf icons for each node?
Thanks
Jay

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kleopatra
Offline
Joined: 2003-06-11

Highlighter as mentioned in the other post is one option. Another is to implement a custom IconValue and let the renderer use it, like in

IconValue iv = new IconValue() {
   Icon getIcon(Object value) {

      // return an icon based on value
     }
}

// here the value will be the user object, SwingX does the unwrapping of the node automatically
TreeCellRenderer r = new DefaultTreeRenderer(iv, sv);


// or here the value will be the node itself
TreeCellRenderer r = new DefaultTreeRenderer(iv, sv, false)

There are examples in the test hierarchy (f.i. search for usage of IconValue in the renderer and swingx package)
HTH
Jeanette

permeable
Offline
Joined: 2010-11-10

Doh!
I've been studying your JXTreeTableDemo and mistakenly assumed that LazyLoadingIconValue() only returned a single icon. I re-ran your demo and discovered the TreeDemoIconValues class. Great work, Jeanette, et. al.

uvoigt
Offline
Joined: 2006-01-26

Sounds like you should have a look on the Highlighter classes.
I don't know for sure if that works but I assume that you can implement a new Highlighter that changes the node icons.