Skip to main content
Known Participant
April 13, 2017
Answered

How to make a scrollbar work in a dialog box.

  • April 13, 2017
  • 3 replies
  • 4819 views

I have a dialog box containing a group with "16 radio button options". My goal is to pack it so it looks smaller. The best way I found it was by adding a scrollbar in the group of buttons, I searched and got a script but could not get it to work. Anyone have any ideas how to help me with this project? Any help is valid. Thank you...

var w = new Window ("dialog", "scrollbar");

     w.orientation = "row"; 

  w.alignChildren = "top";  // insert this line

     w.location = [600,180] 

    var radio_group = w.add ('panel', [0,0,160,190],);

    var sbar = w.add ("scrollbar", [5,0,20,190]);

    

     radio_group.alignChildren = "left";

  radio_group.add ("radiobutton",[5, 10, 100,   0], "Alça e Interior Azul");

  radio_group.add ("radiobutton",[5, 35, 100,  0], "Alça e Interior Vermelho");

     radio_group.add ("radiobutton",[5, 60, 100,   0], "Alça e Interior Preta");

     radio_group.add ("radiobutton",[5, 85, 100,  0], "Alça e Interior Roso");

     radio_group.add ("radiobutton",[5, 110, 100, 0], "Do Tipo Toda Branca");

     radio_group.add ("radiobutton",[5, 135, 100, 0], "Do Tipo Toda Preta");

     radio_group.add ("radiobutton",[5, 160, 100, 0], "Do Tipo Pratiada");

     radio_group.add ("radiobutton",[5, 185, 100, 0], "Do Tipo Caneca Mágica");

     radio_group.add ("radiobutton",[5, 210, 100, 0], "Interior Azul");

     radio_group.add ("radiobutton",[5, 235, 100, 0], "Interior Roso");

     radio_group.add ("radiobutton",[5, 255, 100, 0], "Interior Verde");

     radio_group.add ("radiobutton",[5, 285, 100, 0], "Interior Vermelho");

     radio_group.add ("radiobutton",[5, 310, 100, 0], "Interior Preto");

     radio_group.add ("radiobutton",[5, 335, 100, 0], "Modelo dia dos Pais");

     radio_group.add ("radiobutton",[5, 360, 100, 0], "Caneca de Aluminio");

  radio_group.add ("radiobutton",[5, 385, 100, 0], "Modelo Simples");

  

   

    var btnGroup = w.add("group");

    btnGroup.orientation = "column"; 

    btnGroup.add ('button', {x:90, y:125, width:80, height:25}, 'Ok', {name:'ok'});

    btnGroup.add ('button', {x:240, y:125, width:80, height:25}, 'Cancel', {name:'cancel'});

  // set dialog defaults

  radio_group.children[0].value = true;

function selected_rbutton (rbuttons) {

  for (var i = 0; i < rbuttons.children.length; i++) {

  if (rbuttons.children.value == true) {

  return rbuttons.children.text;

  }

  }

  }

    

  // Linkar com os Scrips.jsx

w.show ()

This topic has been closed for replies.
Correct answer Chuck Uebele

var dlg = new Window('dialog','Dropdown Sample');

var dropList = ["Alça e Interior Azul", "Alça e Interior Vermelho", "Alça e Interior Preta",

"Alça e Interior Roso", "Do Tipo Toda Branca",

"Do Tipo Pratiada", "Do Tipo Caneca Mágica",

"Interior Azul", "Interior Roso", "Interior Verde",

"Interior Vermelho", "Interior Preto", "Modelo dia dos Pais",

"Caneca de Aluminio", "Modelo Simples" ];

dlg.dropDown = dlg.add('dropdownlist', undefined, dropList);

dlg.ok = dlg.add('button', undefined, 'Okay');

dlg.cancel = dlg.add('button', undefined, 'Cancel');

dlg.ok.onClick = function(){

    dlg.close()

    switch(parseInt(dlg.dropDown.selection)){

            case 0:  

            //code here  

            alert("Alça e Interior Azul");  

            break;  

        case 1:  

            //code here  

            alert("Alça e Interior Vermelho");

            break;  

        case 2:  

            //code here  

            alert("Alça e Interior Preta");  

            break;

        }

    }

dlg.cancel.onClick = function(){dlg.close()}

dlg.show()

3 replies

Jarda Bereza
Inspiring
April 13, 2017

I have same question, but I can't use dropdown because I already have many dropdowns.

I guess I should move panel position on scrollbar event or something similar.

Chuck Uebele
Community Expert
Community Expert
April 14, 2017

AFAIK, you can't add a scroll bar to the UI, unfortunately. That's why I'm using tabs now for mine:

Jarda Bereza
Inspiring
April 14, 2017

I created scrollable panel and it works for me. Anyway it is not so good as native support would be.

.

app.bringToFront();

#target Photoshop

var windowResource = """dialog { 

    orientation: 'column',

    alignChildren: ['fill', 'top'], 

    preferredSize:[300, 230],

    text: 'Scroll panel example', 

    margins:15,

   

    scrollPanel: Panel {

        orientation: 'row',

        alignChildren: 'top',

        margins:0,

        spacing:0,

        text: '',

       

        innerScrollPanel: Panel{

            orientation: 'column',

            alignChildren: 'left',

            alignment: 'top',

            margins:0,

            spacing:0,

            text: '',

            properties: {borderStyle:'none'}

        },

       

        panelScrollbar: Scrollbar {

            alignment: 'fill',

            margins:0,

            spacing:0

        }

    },

   

    bottomGroup: Group{

        cancelButton: Button { text: 'Cancel', properties:{name:'cancel'}, size: [120,24], alignment:['right', 'center'] },

        applyButton: Button { text: 'OK', properties:{name:'ok'}, size: [120,24], alignment:['right', 'center'] },

        orientation: 'row'

    }

}"""

var win = new Window(windowResource);

var scrollPanel = win.scrollPanel;

var innerScrollPanel = scrollPanel.innerScrollPanel;

var scrollBar = scrollPanel.panelScrollbar;

scrollPanel.size=[300,400];

innerScrollPanel.preferredSize.width = 300-20;

scrollBar.preferredSize.width = 16;

scrollBar.onChanging = function (){

    var outerPanel = this.parent;

    var innerPanel = outerPanel.children[0];

   

    var innerWidth = innerPanel.bounds.width;

    var innerHeight = innerPanel.bounds.height;

   

    var outerHeight = outerPanel.bounds.height;

   

    this.minvalue = 0;

    this.maxvalue = innerHeight-outerHeight;

   

    this.stepdelta = Math.round(outerHeight / 10);

    this.jumpdelta = Math.round(outerHeight / 5);

   

    var topOffset = -this.value;

    innerPanel.bounds = {x:0, y:topOffset, width:innerWidth,height:innerHeight};

}

// Storing reference to elements

var dropdown = {};

var label = {};

var panel = {};

// Add some sample UI content

for(var i = 0; i < 15; i++){

    panel = win.scrollPanel.innerScrollPanel.add('panel',undefined,'',{justify:'left', borderStyle:'none'});

    panel.orientation = 'row';

    panel.alignment = 'fill';

    label = panel.add('statictext',undefined,"Test dropdown "+i+":");

    dropdown = panel.add('dropdownlist',undefined,["a","b"]);

}

win.bottomGroup.applyButton.onClick = function() {

    win.close();

}

win.show();

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
April 13, 2017

var dlg = new Window('dialog','Dropdown Sample');

var dropList = ["Alça e Interior Azul", "Alça e Interior Vermelho", "Alça e Interior Preta",

"Alça e Interior Roso", "Do Tipo Toda Branca",

"Do Tipo Pratiada", "Do Tipo Caneca Mágica",

"Interior Azul", "Interior Roso", "Interior Verde",

"Interior Vermelho", "Interior Preto", "Modelo dia dos Pais",

"Caneca de Aluminio", "Modelo Simples" ];

dlg.dropDown = dlg.add('dropdownlist', undefined, dropList);

dlg.ok = dlg.add('button', undefined, 'Okay');

dlg.cancel = dlg.add('button', undefined, 'Cancel');

dlg.ok.onClick = function(){

    dlg.close()

    switch(parseInt(dlg.dropDown.selection)){

            case 0:  

            //code here  

            alert("Alça e Interior Azul");  

            break;  

        case 1:  

            //code here  

            alert("Alça e Interior Vermelho");

            break;  

        case 2:  

            //code here  

            alert("Alça e Interior Preta");  

            break;

        }

    }

dlg.cancel.onClick = function(){dlg.close()}

dlg.show()

Ps-DesignAuthor
Known Participant
April 13, 2017

It looks great! Nice work Chuck Uebele To be perfect, it would be nice to have the first item on the list appear when the dialog box opens. Thank you.

In my script this is possible with this line:

lista.selection = 0;

Chuck Uebele
Community Expert
Community Expert
April 13, 2017

Yes you can do that. I normally do that also.

Chuck Uebele
Community Expert
Community Expert
April 13, 2017

Rather than use radio buttons, if you have that many, you should use a drop down list.

Ps-DesignAuthor
Known Participant
April 13, 2017

I found this simple model of Drop dow list:

The problem is that every drop-down list I encounter, the event executes before confirming with the OK button. It would be interesting to choose the option, click ok and then the event.Chuck Uebele How do I change?

var w = new Window ("dialog", "dropdownlist" );

w.orientation = "column";

w.alignChildren = "top"; 

//w.add ("statictext", undefined, "Intens:");

var lista = w.add ("dropdownlist", undefined, [

"Alça e Interior Azul",

"Alça e Interior Vermelho", "Alça e Interior Preta",

"Alça e Interior Roso", "Do Tipo Toda Branca",

"Do Tipo Pratiada", "Do Tipo Caneca Mágica",

"Interior Azul", "Interior Roso", "Interior Verde",

"Interior Vermelho", "Interior Preto", "Modelo dia dos Pais",

"Caneca de Aluminio", "Modelo Simples"

]);

var btnGroup = w.add ("group");

btnGroup.orientation = "row";

lista.selection = 0;

btnGroup.add ("button",{x:240, y:125, width:60, height:25}, 'Cancel', {name:'cancel'});

btnGroup.add ("button",{x:90, y:125, width:60, height:25}, "OK");

btnGroup.alignment = "right";

lista.onChange = function(){ 

      switch(parseInt( lista.selection)){ 

        case 0: 

            //code here 

            alert("Alça e Interior Azul"); 

            break; 

        case 1: 

            //code here 

            alert("Alça e Interior Vermelho");

            break; 

        case 2: 

            //code here 

            alert("Alça e Interior Preta"); 

            break;         

        }     

    } 

w.show ();

Chuck Uebele
Community Expert
Community Expert
April 13, 2017

Don't put the code to do something in the onChange function for the dropdownlist. Add it to an onClick function for the Okay button.