Table Cell Renderer

I need to vary the background color of a cell based on it’s contents.

I have the following code to return the default cell renderer, change the background color and then reset it. I am unsure if i need to Override/Implement the TableCellRenderer. If so, I don’t have the foggiest idea how to do it.

[code]from javax.swing import JTable
from javax.swing import JLabel
from javax.swing.table import *

import system
Table = event.source.parent.getComponent(‘Table 2’)
Table2 = Table.getTable()

dt = Table2.getCellRenderer(1,1)


Table2.setDefaultRenderer(Table2.class, dt)

Data = event.source.parent.getComponent(‘Table 2’).data



I just figured out that the Background Color Column and the Background Color List in the table customizer do what I want them to do.

See attached Image

I’m glad you got it to work. For what it’s worth, in Ignition 7.6, there is a new way to do this that is more in line with what you originally tried: extension functions. You can now override the Table’s implementation of getBackgroundColorAt() and provide a color for any cell.

Could someone please provide more of an example regarding how to use the extension function in this case? I’m trying to reference a custom property (e.g. “lowValue”) to compare to the cell’s value and therefore change the background color. I feel like I’m pretty close, but I just can’t quite get there.

print self.getParent.im_self returns the name of my table, but I don’t know how to access the custom properties.

Only been working with Ignition for 2 weeks, so please be patient with me. :thumb_right:

You won’t find much on extension functions in here, because they’re a very new feature, introduced in Ignition 7.6.0.

You should be able to access custom properties simply by doing a [tt]self.propertyName[/tt] reference. But - you found a bug! That didn’t work. (It’ll work in 7.6.2).

In the meantime you can do [tt]self.getPropertyValue(‘propertyName’)[/tt]

Hope this helps,