1 Reply Latest reply on Feb 24, 2018 2:12 PM by Tomas Sinkunas

    How to Move UI button or any element in x and y axis specifically after creation?

    manjunathk23388540 Level 1

      //Below script generates Window,Panel with button

      //I would like to move button/UI element in x and y axis to desired location

      //Could someone please let me know to achieve it?

       

       

       

      function myScript(thisObj){

          function myScript_buildUI(thisObj){

             

              var myPanel = (thisObj instanceof Panel) ? thisObj : new Window("palette", "tools",undefined ,{resizeable:true});

          

              

                var resAbout="panel{orientation:'row',\

                                                t1:Button{},\

                                                 \

                                                \

                                                }";     

                                               

                      myPanel.grp=myPanel.add(resAbout);

       

          myPanel.preferredSize=[500,200];

         myPanel.grp.preferredSize=[500,200];

                 myPanel.grp.margins=2;

                

       

        

      return myPanel;

       

       

      }

       

       

      var myScriptPal = myScript_buildUI(thisObj);

       

       

          if((myScriptPal != null) && (myScriptPal instanceof Window)) {

              myScriptPal.center();

              myScriptPal.show();

          }

       

       

      }

       

       

            myScript(this);

        • 1. Re: How to Move UI button or any element in x and y axis specifically after creation?
          Tomas Sinkunas Adobe Community Professional

          Button object as a location property that you can modify. Take a look at this snippet:

           

          (function (thisObj) {
              buildUI(thisObj);
          
          
              function buildUI(thisObj) {
                  var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script", undefined, {
                      resizeable: true
                  });
          
          
                  // Resize the pallete
                  win.preferredSize = [400, 200];
          
          
                  // Create a dummy button
                  var btn = win.add("button", undefined, "OK");
                  btn.onClick = function () {
          
          
                      // Generate rnadom X and Y values
                      var randomX = Math.random() * 400;
                      var randomY = Math.random() * 200;
          
          
                      // Change buttons position
                      this.location = [randomX, randomY];
          
          
                  }
          
          
                  // Handle window resizing
                  win.onResizing = win.onResize = function () {
                      this.layout.resize();
                  };
          
          
                  // Show panel
                  if (win instanceof Window) {
                      win.center();
                      win.show();
                  } else {
                      win.layout.layout(true);
                      win.layout.resize();
                  }
              }
          
          
          })(this);