Table component getBackgroundAt example

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

There’s a good example in the manual here.

1 Like

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.

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.

1 Like

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":
if col == 5 and value == "No":

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

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

if col == 5:
    if value == "Yes":
    if value == "No":

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

1 Like

Thank you but I’m not sure how to accomplish this. I tried what is below:

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

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.