# Table component getBackgroundAt example

**URL:** <https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [May 17, 2018, 12:48pm UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073 "2018-05-17T12:48:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrowe](https://avatars.discourse-cdn.com/v4/letter/r/c57346/32.png) [@rrowe](https://forum.inductiveautomation.com/u/rrowe)\
**Post date:** [May 17, 2018, 12:48pm UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073/1 "2018-05-17T12:48:53Z")

</div>

Does anyone have a script that I could use as a reference for the table component’s getBackgroundAt extension function?

---

<div class="post-metadata">

**Author:** ![Connor](https://avatars.discourse-cdn.com/v4/letter/c/e99b99/32.png) [@Connor](https://forum.inductiveautomation.com/u/Connor)\
**Post date:** [May 18, 2018, 2:58pm UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073/2 "2018-05-18T14:58:03Z")

</div>

There’s a good example in the manual [here](https://docs.inductiveautomation.com/display/DOC79/Extension+Functions).

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [January 10, 2019, 12:50am UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073/3 "2019-01-10T00:50:36Z")

</div>

Is there a way to call getBackgroundAt() on a specific action, and not by the default settings? It seems that it is called each time my Table is clicked or the scroll bar is moved… this is leading to a very slow window!

For example, would there be code that I could put within getBackgroundAt that would prevent it from being called right away? I tried calling getBackgroundAt from onFocusGained and this didn’t seem to work.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 10, 2019, 1:44pm UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073/4 "2019-01-10T13:44:50Z")

</div>

Methods that participate in painting must be designed to execute extremely fast. The best way to ensure speed is to arrange your code to only use data that is already in properties of the component. Add custom properties and/or JComponent client properties as needed. Bind all external data (tags, queries, etc) to those custom properties so the painting method doesn’t spend any time going to get it.

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [January 15, 2019, 2:24am UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073/5 "2019-01-15T02:24:12Z")

</div>

Okay, we currently have as below. Seems inefficient to run this so many times since the table is only updating every 5 mins or with user input…

```
from java.awt import Color

if col == 5 and value == "Yes":
	return Color.green
	
if col == 5 and value == "No":
	return Color.red
```

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [January 18, 2019, 7:36pm UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073/6 "2019-01-18T19:36:21Z")

</div>

Okay, it seems the java.awt import was slowing things down.  
returning the html colors ( **#00ff00** ) seems to be much faster.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 18, 2019, 7:41pm UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073/7 "2019-01-18T19:41:11Z")

</div>

If you want it faster, put the Color import into a script module, then do this:

```auto
if col == 5:
    if value == "Yes":
        return shared.gui.Color.green
    if value == "No":
        return shared.gui.Color.red

```

It avoids constructing a color from the hex string in the background.

---

<div class="post-metadata">

**Author:** ![mriederer](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@mriederer](https://forum.inductiveautomation.com/u/mriederer)\
**Post date:** [January 19, 2019, 12:45am UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073/8 "2019-01-19T00:45:59Z")

</div>

Thank you but I’m not sure how to accomplish this. I tried what is below:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/971f834a4cb88cf18cbe13ce45e3e53f4a1f0c8d.png)

Also, I tried returning different colors via Color.green, or java.awt.Color.green and still no luck.  
What should I be returning from this function?

---

<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:** [January 19, 2019, 12:58am UTC](https://forum.inductiveautomation.com/t/table-component-getbackgroundat-example/18073/9 "2019-01-19T00:58:52Z")

</div>

You don’t actually need to define a function here - just defining the constant value will work. If `shared.gui` just contains:  
`from java.awt import Color`  
You’re bringing `java.awt.Color` into the `shared.gui` namespace, and you should be able to use it as Phil showed above.
