Skip to main content
Known Participant
Oct 27, 2015 3:33 PM UTC
Answered

How to change size and color of "staticText"??

Can someone plz share how to change size and color of "staticText" object??

function buildUI(thisObj) {

var myPanel = (thisObj instanceof Panel) ? thisObj:new Window('palette', 'Stress Reducers',undefined, {resizable: true});

var txt=myPanel.add("staticText",[0,0,100,20],"txt");

//txt. newFont, fontSize,color?????

  return myPanel;

}

var myToolsPanel = buildUI(this);

This topic is closed to new replies. Start a new post to keep the conversation going.
David TornoCorrect answer
Legend
Oct 28, 2015 10:10 PM UTC

Am using the same version as well..

AE2014..Windows 8.1


I did a quick test on a PC at the office and it seems that Gill Sans is not a stock PC font. You might comment those out or change them to a stock font like Helvetica or something. Once I removed that it launched on PC just fine.

12 replies

Dan Ebberts
Community Expert
Community Expert
Oct 27, 2015 8:24 PM UTC

I haven't done font size, but color you can do like this:

var txt=myPanel.add("staticText",[0,0,100,20],"txt");

var theColorArray = [1, 0.1, 0.2, 1];

var g = txt.graphics;

var c = g.newPen(g.PenType.SOLID_COLOR,theColorArray,1);

g.foregroundColor = c;

Specifying the font attributes is covered in the JavaScript Tools Guide. Please post an example if you figure out how to make it work.

Dan

Translate
Legend
Oct 28, 2015 12:07 AM UTC

You setup a new font like so...

var arielBold24Font = ScriptUI.newFont("Arial", ScriptUI.FontStyle.BOLD, 24);

Apply it to your text like so...

text.graphics.font = arielBold24Font;

Translate
Legend
Oct 28, 2015 12:24 AM UTC

Here's a better example of color and font use.

var win = new Window("palette", "Fonts", undefined);

win.orientation = "column";

var winGraphics = win.graphics;

var red = winGraphics.newPen(winGraphics.BrushType.SOLID_COLOR, [1,0,0], 1);

var blue = winGraphics.newPen(winGraphics.BrushType.SOLID_COLOR, [0,0,1], 1);

var gray = winGraphics.newPen(winGraphics.BrushType.SOLID_COLOR, [0.5,0.5,0.5], 1);

//Create fonts

var ariaBold24Font = ScriptUI.newFont("Arial", ScriptUI.FontStyle.BOLD, 24);

var arialReg10Font = ScriptUI.newFont("Arial", ScriptUI.FontStyle.REGULAR, 10);

var arialItalic18Font = ScriptUI.newFont("Arial", ScriptUI.FontStyle.ITALIC, 18);

var gillSansBold20Font = ScriptUI.newFont("Gill Sans", ScriptUI.FontStyle.BOLD, 20);

//Sample text

var a = win.add("statictext", undefined, "abcdefghijklmnopqrstuvwxyz");

var b = win.add("statictext", undefined, "abcdefghijklmnopqrstuvwxyz");

var c = win.add("statictext", undefined, "abcdefghijklmnopqrstuvwxyz");

var d = win.add("statictext", undefined, "abcdefghijklmnopqrstuvwxyz");

var e = win.add("statictext", undefined, "abcdefghijklmnopqrstuvwxyz");

var f = win.add("statictext", undefined, "abcdefghijklmnopqrstuvwxyz");

//Apply font styles

a.graphics.font = ariaBold24Font;

b.graphics.font = arialReg10Font;

c.graphics.font = arialItalic18Font;

d.graphics.font = gillSansBold20Font;

e.graphics.font = ariaBold24Font;

f.graphics.font = gillSansBold20Font;

//Apply color

a.graphics.foregroundColor = blue;

e.graphics.foregroundColor = red;

f.graphics.foregroundColor = gray;

win.center();

win.show();

Translate