5 Replies Latest reply on Sep 18, 2016 1:16 PM by Loic.Aigon

    list item backgroundcolor

    scriptworker

      Hello,

       

      I'd like to set the backgroundcolor of a listitem

      in a listbox. Is that possible? If yes, how can it

      be done?

       

      Kind regards,

      Michel

        • 1. Re: list item backgroundcolor
          tpk1982 Level 4

          something like this?

           

          var w = new Window ("dialog");

          var myList = w.add ("listbox");

          for (var i = 1; i < 5; i++) {

          myList.add ("item", "Line_" + String (i));

          myList.graphics.backgroundColor = myList.graphics.newBrush (w.graphics.BrushType.SOLID_COLOR, [0.5, 0.0, 0.0]);

          myList.graphics.foregroundColor = myList.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [1, 0.5, 0.5], 1);

          }

          myList.preferredSize = [100,100];

          w.show ();

          • 2. Re: list item backgroundcolor
            scriptworker Level 1

            Thank for the answer. I am almost there.

            I want to set the background of each item

            separately. Is that possible?

             

            Kind regards,

            Michel

            • 3. Re: list item backgroundcolor
              scriptworker Level 1

              I've read through the forum about this.

              Seems to be extremely difficult to get

              a per item background color in a listbox.

               

              Michel

              • 4. Re: list item backgroundcolor
                scriptworker Level 1

                I've finally found a solution I can work with.

                I've abandoned the listbox. I am using panels now.

                With many thanks to Peter Kahrel and his ScriptUI pdf.

                 

                Michel

                 

                 

                 

                w = new Window('dialog');

                w.maximumSize.height = 300;

                var panel = w.add ('panel {alignChildren: "left"}');

                var scrollGroup = panel.add ('group {orientation: "column"}');

                 

                for (var i = 0; i <= 5; i++)

                {

                  item_ = scrollGroup.add ('group {orientation: "column"}');

                  text_ = item_.add('statictext', undefined, 'Label ' + i);

                  item_.addEventListener('click',function()

                  {

                       removeBackgrounds();

                       this.graphics.backgroundColor = this.graphics.newBrush (this.graphics.BrushType.SOLID_COLOR, [1, 0.0, 0.0]);

                  });

                }

                 

                var scrollBar = panel.add ('scrollbar {stepdelta: 20}');

                // Move the whole scroll group up or down

                scrollBar.onChanging = function () {

                scrollGroup.location.y = -1 * this.value;

                }

                 

                w.onShow = function() {

                // Set various sizes and locations when the window is drawn

                panel.size.height = w.size.height-20;

                scrollBar.size.height = w.size.height-40;

                scrollBar.size.width = 20;

                scrollBar.location = [panel.size.width-30, 8];

                scrollBar.maxvalue = scrollGroup.size.height - panel.size.height + 15;

                };

                w.show();

                 

                 

                function removeBackgrounds()

                {

                  for (var j=0; j<scrollGroup.children.length; j++)

                  {

                  scrollGroup.children[j].graphics.backgroundColor = scrollGroup.children[j].graphics.newBrush (scrollGroup.children[j].graphics.BrushType.SOLID_COLOR, [0.94, 0.94, 0.94]);

                  }

                }

                • 5. Re: list item backgroundcolor
                  Loic.Aigon Adobe Community Professional

                  For what it's worth, this group/list trickery may fail to display every single group of the serie. For example, if the counter is higher than 34, then all the groups from 35 to n won't be displayed (it may vary depending on screens sizes and settings). But at some point it fails.