Change text font by scripting


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

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

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)"

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.

I set up an experiment where I forcibly changed the label's size using this:

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

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

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>"

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

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

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

1 Like

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.

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.

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

Maybe the Synthetica.font.scaleFactor?

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

1 Like

Did y'all turn off 'Scale Font' in the layout settings?

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


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


Yes thanks!
It worked for me too