# controlP5 Slider and Buttons as arrays

**URL:** <https://discourse.processing.org/t/controlp5-slider-and-buttons-as-arrays/39405>\
**Category:** Libraries\
**Created:** [October 23, 2022, 9:45pm UTC](https://discourse.processing.org/t/controlp5-slider-and-buttons-as-arrays/39405 "2022-10-23T21:45:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@andy](https://discourse.processing.org/u/andy)\
**Post date:** [October 23, 2022, 9:45pm UTC](https://discourse.processing.org/t/controlp5-slider-and-buttons-as-arrays/39405/1 "2022-10-23T21:45:33Z")

</div>

Using controlP5,

I need to create 40 sliders and 40 buttons, I use to use Delphi and could create an array of scrollbars with associated buttons. Can I do the same with processing, if so, can anyone could shed some light onto how to go about it.

The slider positions and button captions need to be set both manually and at runtime. The button captions will reflect the scroll bar positions. some other code will also change the slider positions.

So I would in code set the position of a scroll bar something like:  
scrollbar(X).position=328  
button.caption= scrollbar(X).position

Trying to avoid creating 40 sets of these.

```auto
Slider f1 = controlP5.addSlider("SLIDR1")
.setRange(SLIDRmin,255)
.setValue(SLIDRdefault)
.setPosition(SLIDRleftposition,SLIDRtopY)
.setSize(SLIDRwidth,SLIDRheight)
.setColorActive(0xffffffff)
.setLabelVisible(false);
f1.setSliderMode(Slider.FLEXIBLE)
;

bt1 = controlP5.addButton("bt1");
bt1.setPosition(SLIDRleftposition, SLIDRheight+SLIDRtopY+2);
bt1.setSize(SLIDRwidth, SLIDRwidth);
bt1.setFont(createFont("SansSerif", 14));
bt1.setColorCaptionLabel(#ffffff);
bt1.setColorBackground(#000000);
bt1.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
;    

```

---

<div class="post-metadata">

**Author:** ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)\
**Post date:** [October 23, 2022, 11:24pm UTC](https://discourse.processing.org/t/controlp5-slider-and-buttons-as-arrays/39405/2 "2022-10-23T23:24:19Z")

</div>

There is another recent post by Darthbray that might be worth your while:

> [@I can't figure out how to make this array compatible with my Button class](https://discourse.processing.org/t/i-cant-figure-out-how-to-make-this-array-compatible-with-my-button-class/39403):
>
> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147) I’m trying to create a randomly generated chord progression program but I haven’t even reached that part yet, I’m stuck on making an array with my button class. The error message is “Type mismatch: cannot convert from sketch\_221023a.Button to int,” which doesn’t make sense because I’ve followed 3 tutorials on how to implement arrays into classes and I don’t see what’s wrong. (please excuse some redundancies and messy att…

Rather than using a library such as controlP5, Darthbray wrote his/her own `Button` class. An array is made to hold 50 of these, which are created (and added to the array) a little bit later.

Similar to Darthbray’s `Button` class, you could write your own `SliderSet` class that groups together a slider and its associated buttons.
