3 Replies Latest reply on Jan 29, 2010 1:26 PM by Michael L Hale

    Change the font size of a StaticText (or any) object via ScriptUIGraphics class?

    badaboom_55 Level 1

      Hello all,

       

      I'm trying to create a dialog box for a custom Photoshop Script, which I've successfully done.

       

      However, I now want to basically add a StaticText element to a Panel that contains a little note/warning to the user. I want this note to be a smaller font size than the other elements/labels within the dialog, but I'm having trouble figuring out how to change the StaticText element's associated ScriptUIGraphics and ScriptUIFont objects...

       

      Can someone please show me the syntax to apply a new font size to a StaticText element, which I will apparently need to do via the onDraw() callback function?

       

      Thanks!

       

      EDITORIAL: Adobe should really get their !@$#! together and provide an ExtendScript Language Reference that operates the same as the ActionScript3.0 Language and Components Reference... with examples and all.... instead of LITERALLY HALF A DOZEN PDFs with disjointed and hodge-podge documentation on Objects and Classes.

        • 1. Re: Change the font size of a StaticText (or any) object via ScriptUIGraphics class?
          Michael L Hale Level 5
          createDialog = function ( ) {
             var dlg = new Window( 'dialog', 'Font size example' );
             dlg.stExample = dlg.add( 'statictext', undefined, 'Example' );
             dlg.stExample.graphics.font = ScriptUI.newFont("Arial","REGULAR",9); 
             dlg.btnPnl = dlg.add( 'panel', undefined );
             dlg.btnPnl.orientation = "row";
             dlg.btnPnl.alignment = "right";
             dlg.btnPnl.preferredSize [ 80, 80 ]
             dlg.btnPnl.okBtn = dlg.btnPnl.add( 'button', undefined, 'Ok', { name:'ok' });
             dlg.btnPnl.cancelBtn = dlg.btnPnl.add( 'button', undefined, 'Cancel', { name:'cancel' });
             return dlg;
          };
          initializeDialog = function( w ) {
             // Set up initial control states
          
              with ( w.btnPnl ) {
                   // The Ok and Cancel buttons close this dialog
                   okBtn.onClick = function ( ) { this.parent.parent.close( 1 ); };
                   cancelBtn.onClick = function ( ) { this.parent.parent.close( 2 ); };
                }   
           }
          
          runDialog = function( w ) {
             return w.show( );
          };
          var win = createDialog();
          initializeDialog(win);
          runDialog(win)
          
          • 2. Re: Change the font size of a StaticText (or any) object via ScriptUIGraphics class?
            badaboom_55 Level 1

            Thanks...I couldn't find an example of line 4 anywhere!!

             

            Quick question... I would've written lines 2 & 3 of the function a bit differently than your example... I wouldn't have explicitly prepended "dlg." to "stExample", I would've just used "var" to instantiate "stExample":

             

               var stExample = dlg.add( 'statictext', undefined, 'Example' );
               stExample.graphics.font = ScriptUI.newFont("Arial","REGULAR",9);

             

            Both seem to work when I test... is there a semantic/logical why one method is preferrable over the other?

            • 3. Re: Change the font size of a StaticText (or any) object via ScriptUIGraphics class?
              Michael L Hale Level 5

              I think that it's mostly a matter of style. One downside to making a variable reference to each control widget is it uses more memory and increases the chance of a name conflict.

              1 person found this helpful