How to change the background color for Tag Browse Tree component

Hi,
Is there any option to change the background color of tag browse tree?

image

I was able to from a button using scripting:

from java.awt import Color
from javax.swing import JViewport
from com.inductiveautomation.ignition.client.util.gui.tree import AutoscrollingJTree
tagBrowseTree = event.source.parent.getComponent('Tag Browse Tree')
for component in tagBrowseTree.getComponents():
	if isinstance(component, JViewport):
		for subComponent in component.getComponents():
			if isinstance(subComponent, AutoscrollingJTree):
				subComponent.background = Color.green
				break
		break

The preceding code produces the following result:
image

The code just loops through the tag browser's subcomponents until it finds the autoscrollingJTree, and applies the specified color.

Edit: this works from a button's actionPerformed script too, but the code is much simpler:

from java.awt import Color
tagBrowseTree = event.source.parent.getComponent('Tag Browse Tree')
tagBrowseTree.getComponent(0).getComponent(0).background = Color.orange

Output:
image

1 Like

Hi,
Is it possible to change the font color, icons present in that too?

I'm not sure. Since I last answered this, I've discovered the getTree method that is arguably better, but I don't know why the setForeground method doesn't work with it:

from java.awt import Color
tagBrowseTree = event.source.parent.getComponent('Tag Browse Tree').getTree()
tagBrowseTree.background = Color.orange
1 Like

I couldn't find an intuitive way to do this, but the below approach works. This script is designed for the propertyChange event handler of the tag browse tree:

if event.propertyName == 'rootNodePath':
	from java.awt import Color
	component = event.source.getTree().getCellRenderer()
	textNonSelectionColorField = component.getClass().getDeclaredField('textNonSelectionColor')
	textNonSelectionColorField.setAccessible(True)
	textNonSelectionColorField.set(component, Color.blue)

Result:
image

It looks like there are at least two approaches that could work here. It is possible that something similar to the above approach could be employed on the following renderer fields: 'folderIcon', 'closedFolderIcon', 'folderIconSelected', 'closedFolderIconSelected', 'standardTag', 'standardTagSelected', 'udtTag', 'udtTagSelected', 'udtInstance', 'errorIcon', 'loadingIcon', 'atomic', and 'atomicSelected'

Another approach could be to directly overwrite the icons in their respective jar files. It looks like they all live here: [...]/.ignition/cache/resources/platform/client-api-8.1.xx.jar/[...]/images/tags/

Hi Justinedwards,
Thank you for your support. Now i am able to change the font and background color. :blush:

1 Like