# Treeview, change node icon when treeview is disabled

**URL:** <https://forum.inductiveautomation.com/t/treeview-change-node-icon-when-treeview-is-disabled/11461>\
**Category:** Ignition\
**Created:** [April 4, 2016, 7:02pm UTC](https://forum.inductiveautomation.com/t/treeview-change-node-icon-when-treeview-is-disabled/11461 "2016-04-04T19:02:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [April 4, 2016, 7:02pm UTC](https://forum.inductiveautomation.com/t/treeview-change-node-icon-when-treeview-is-disabled/11461/1 "2016-04-04T19:02:01Z")

</div>

For the treeview component, we can modify, node icon’s.  
But when the treeview is disabled, a default node icon (file icon) is used instead of the node icon’s (Icon and SelectedIcon column in the tree view dataset) ?  
 ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")

---

<div class="post-metadata">

**Author:** ![camatt3](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@camatt3](https://forum.inductiveautomation.com/u/camatt3)\
**Post date:** [June 6, 2018, 3:40am UTC](https://forum.inductiveautomation.com/t/treeview-change-node-icon-when-treeview-is-disabled/11461/2 "2018-06-06T03:40:22Z")

</div>

Did you ever resolve this? I’m facing the same issue.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [June 6, 2018, 6:12am UTC](https://forum.inductiveautomation.com/t/treeview-change-node-icon-when-treeview-is-disabled/11461/3 "2018-06-06T06:12:09Z")

</div>

No workaround found for this case 😭

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 6, 2018, 4:56pm UTC](https://forum.inductiveautomation.com/t/treeview-change-node-icon-when-treeview-is-disabled/11461/4 "2018-06-06T16:56:12Z")

</div>

The disabled icon comes from the underlying DefaultTreeCellRenderer’s `getTreeCellRendererComponent` (see [here](http://www.docjar.com/html/api/javax/swing/tree/DefaultTreeCellRenderer.java.html), line 472) which calls out to the look-and-feel to return a grey-tinted version of the ‘default’ leaf icon (the page/folder, respectively). To override that behavior, you would have to provide a different implementation of [`TreeCellRendererComponent`](https://docs.oracle.com/javase/7/docs/api/javax/swing/tree/TreeCellRenderer.html) to the JTree inside the [`PMITreeView`](http://files.inductiveautomation.com/sdk/javadoc/ignition79/795/com/inductiveautomation/factorypmi/application/components/PMITreeView.html) component.

---

<div class="post-metadata">

**Author:** ![camatt3](https://avatars.discourse-cdn.com/v4/letter/c/22d042/32.png) [@camatt3](https://forum.inductiveautomation.com/u/camatt3)\
**Post date:** [June 7, 2018, 2:12am UTC](https://forum.inductiveautomation.com/t/treeview-change-node-icon-when-treeview-is-disabled/11461/5 "2018-06-07T02:12:04Z")

</div>

Thanks, got it to work. I’ve included my script below.  
The script is a custom method on the Tree View component.

```auto
def setupTreeCellRenderer(self):
	"""
	Arguments:
		self: A reference to the component instance this method is invoked on. This argument
		  is automatic and should not be specified when invoking this method.
	"""
	from javax.swing.tree import DefaultTreeCellRenderer
	from javax.swing import UIManager
	
	# Create a subclass of DefaultTreeCellRenderer
	class CustomRenderer(DefaultTreeCellRenderer):
	
		originalRenderer = None
		
		# init
		def __init__ (me, tree):
			me.originalRenderer = tree.getCellRenderer()
		
		# Use the original cell renderer to get a Tree Cell Renderer Component, then simply
		# modify the icon it uses.
		def getTreeCellRendererComponent(me, tree, value, sel, expanded, leaf, row, hasFocus):
			tcrc = me.originalRenderer.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus)
			if not tree.isEnabled():
				icon = tcrc.getIcon()
				laf = UIManager.getLookAndFeel()
				# Get a disabled (grey) version of the icon
				disabledIcon = laf.getDisabledIcon(tree, icon)
				if (disabledIcon != None): icon = disabledIcon
				# Set the disabled icon
				tcrc.setDisabledIcon(icon)
			return tcrc
	
	# Assign the cell renderer of the component's underlying tree view
	# to a new instance of our custom Renderer class
	tree = self.getComponent(0).getComponent(0)
	tree.setCellRenderer(CustomRenderer(tree))

```
