# Change text font by scripting

**URL:** <https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [December 15, 2022, 10:40am UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664 "2022-12-15T10:40:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@David\_Gonzalez](https://forum.inductiveautomation.com/u/David_Gonzalez)\
**Post date:** [December 15, 2022, 10:40am UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/1 "2022-12-15T10:40:30Z")

</div>

Hello,

I need to change the font of a label with a condition  
but it seems there is a bug or I am doing it wrong, for example:

from java.awt import Font  
nom = event.source.parent.getComponent('ioParamNom')  
nom.font = Font('MV boli', Font.ITALIC, 30)

the inital text font is ('Dialog', Font.BOLD, 10)

The font works and the style works but not the size  
So I tried changing the Font and the style, always works but it doesn't take the size  
I tried testing with button, when I click the button, it runs the code above and I see that the size changes to 30 for a second but comes back to inital 10

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 15, 2022, 11:21am UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/2 "2022-12-15T11:21:00Z")

</div>

> [@David\_Gonzalez](#):
>
> it runs the code above and I see that the size changes to 30 for a second but comes back to inital 10

I am unable to replicate this behavior. I change the font of a label using your script, and it works perfectly. I even closed the designer and reopened it. It remembered.

What version of ignition are you using? Presently, I'm testing on 8.1.20

---

<div class="post-metadata">

**Author:** ![David\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@David\_Gonzalez](https://forum.inductiveautomation.com/u/David_Gonzalez)\
**Post date:** [December 15, 2022, 12:34pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/3 "2022-12-15T12:34:11Z")

</div>

I'm on V8.1.18

It's weird because when I run it in the designer pressing the button play, it works  
It doesn't work when I launch it from "Tools-\>Launch Project-\>Launch (windowed)"

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 15, 2022, 12:41pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/4 "2022-12-15T12:41:50Z")

</div>

Yup; you are correct. When I run it outside of the designer in an actual session, there is no noticeable change in size. I wonder if this is because the font automatically changes size proportionally to the label, and in the actual session, the label itself holds its dimensions.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 15, 2022, 12:59pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/5 "2022-12-15T12:59:05Z")

</div>

I set up an experiment where I forcibly changed the label's size [using this](https://docs.inductiveautomation.com/display/DOC81/system.gui.transform):

```auto
system.gui.transform(nom, nom.x, nom.y, 200, 200)

```

It did change the size of the label, but if the vertical alignment is not set to "Top," the label appears to move when the width and height change

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 15, 2022, 1:05pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/6 "2022-12-15T13:05:48Z")

</div>

Injecting HTML into the label changed the font size as expected in the actual session:

```auto
from java.awt import Font
nom = event.source.parent.getComponent('ioParamNom')
nom.font = Font('MV boli', Font.ITALIC, 30)
labelText = "TestText"
nom.text = "<html><p style='font-size:30px'>" + labelText + "</p></html>"

```

---

<div class="post-metadata">

**Author:** ![David\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@David\_Gonzalez](https://forum.inductiveautomation.com/u/David_Gonzalez)\
**Post date:** [December 15, 2022, 1:39pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/7 "2022-12-15T13:39:31Z")

</div>

Yes! Thanks  
It worked on a label even with this short code:

```auto
nom.text = "<html><font size=30>" + labelText
```

BUT, I tried with a "Text Field" and a "Text Area", it doesn't work

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 15, 2022, 2:08pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/9 "2022-12-15T14:08:05Z")

</div>

> [@David\_Gonzalez](#):
>
> "Text Field" and a "Text Area",

I'm able to replicate this. The font size doesn't change. If I highlight the text, it changes for a second, and then snaps back to the smaller size.

It works as expected in the designer though.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 15, 2022, 2:53pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/10 "2022-12-15T14:53:20Z")

</div>

I even set up a style customizer tied to a custom property I called fontSize. When I changed the custom property, it was the same result. The style was applied for a moment, and then, it was immediately overwritten.

Again, the approach worked as expected in the designer, but not in an actual session.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [December 15, 2022, 3:12pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/11 "2022-12-15T15:12:04Z")

</div>

Will probably have to use Java (Perhaps the UIManager) in order to get this to work.

> **[Synthetica - Java Look And Feel](https://www.jyloo.com/synthetica/customize/#General)**
>
> Jyloo Software is a leading Java Look and Feel and Swing component provider. Based on Java Swing technology, Jyloo, JAVASOFT software products are user friendly, come along with a modern look, provide consistency and a high grade of customizability.

Maybe the `Synthetica.font.scaleFactor`?

There are some limitations to what Swing is capable of though.

---

<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:** [December 15, 2022, 4:23pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/12 "2022-12-15T16:23:48Z")

</div>

Did y'all turn off 'Scale Font' in the layout settings?  
[https://docs.inductiveautomation.com/display/DOC81/Working+with+Vision+Components#WorkingwithVisionComponents-RelativeLayout](https://docs.inductiveautomation.com/display/DOC81/Working+with+Vision+Components#WorkingwithVisionComponents-RelativeLayout)

Note that even if the component is _anchored_, the 'Scale Font' checkbox still applies.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 15, 2022, 4:45pm UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/13 "2022-12-15T16:45:34Z")

</div>

> [@paul-griffith](#):
>
> l turn off 'Scale Font' in the layout settings

That needs to be marked as the solution. It fixed the problem in my test environment on all components.

---

<div class="post-metadata">

**Author:** ![David\_Gonzalez](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@David\_Gonzalez](https://forum.inductiveautomation.com/u/David_Gonzalez)\
**Post date:** [December 16, 2022, 6:49am UTC](https://forum.inductiveautomation.com/t/change-text-font-by-scripting/67664/14 "2022-12-16T06:49:48Z")

</div>

Yes thanks!  
It worked for me too
