# Value for foreground property when assigning to label or text through code

**URL:** <https://forum.inductiveautomation.com/t/value-for-foreground-property-when-assigning-to-label-or-text-through-code/18167>\
**Category:** Ignition\
**Created:** [May 25, 2018, 3:38am UTC](https://forum.inductiveautomation.com/t/value-for-foreground-property-when-assigning-to-label-or-text-through-code/18167 "2018-05-25T03:38:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ella\_ramos](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ella_ramos/32/3455_2.png) [@ella\_ramos](https://forum.inductiveautomation.com/u/ella_ramos)\
**Post date:** [May 25, 2018, 3:38am UTC](https://forum.inductiveautomation.com/t/value-for-foreground-property-when-assigning-to-label-or-text-through-code/18167/1 "2018-05-25T03:38:22Z")

</div>

Hello,

I wish the Ignition documentation is clearer about what value to use for the scripting function like ".foreground"

```
	> event.source.parent.getComponent('notLbl').foreground = "green"

```

I tried using hex \> "#fff", rgb \> "255,255,2555", and the actual color name \> "white" but it still gives me this error.

> Traceback (most recent call last):  
> File "event:actionPerformed", line 20, in   
> TypeError: can't convert 'white' to java.awt.Color

Maybe this is so simple, but just frustrating that I cant find it anywhere how to do this.

thanks for any help.

---

<div class="post-metadata">

**Author:** ![Kleppe85](https://avatars.discourse-cdn.com/v4/letter/k/c4cdca/32.png) [@Kleppe85](https://forum.inductiveautomation.com/u/Kleppe85)\
**Post date:** [May 25, 2018, 5:03am UTC](https://forum.inductiveautomation.com/t/value-for-foreground-property-when-assigning-to-label-or-text-through-code/18167/2 "2018-05-25T05:03:25Z")

</div>

Hi, try using this function.

[https://docs.inductiveautomation.com/display/DOC79/system.gui.color](https://docs.inductiveautomation.com/display/DOC79/system.gui.color)

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [May 25, 2018, 7:01am UTC](https://forum.inductiveautomation.com/t/value-for-foreground-property-when-assigning-to-label-or-text-through-code/18167/3 "2018-05-25T07:01:43Z")

</div>

The error tells you that foreground is expecting to be set with a java.awt.Color object. As Kleppe85 stated, you can get this color with system.gui.color(). Another option is to import the Color class and use it directly.

```auto
from java.awt import Color
path.to.component.color = Color(r,b,g,a)
path.to.component.othercolor = Color.BLACK

```

Generally speaking, use system.gui.color if you dont understand how imports work and the impact they could have on your code.

---

<div class="post-metadata">

**Author:** ![ella\_ramos](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ella_ramos/32/3455_2.png) [@ella\_ramos](https://forum.inductiveautomation.com/u/ella_ramos)\
**Post date:** [May 28, 2018, 1:34am UTC](https://forum.inductiveautomation.com/t/value-for-foreground-property-when-assigning-to-label-or-text-through-code/18167/4 "2018-05-28T01:34:35Z")

</div>

this works! Thanks a lot!
