Scrollablelist set Item selected from code

Hello everyone! i’m a new on processing forum.
I make a Scrolablelist from ControlP5 library and I would like to change via code the selected item:

import controlP5.*;
import java.util.*;

ControlP5 cp5;

void setup() {
  size(400, 400);
  cp5 = new ControlP5(this);
  List l = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h");
  /* add a ScrollableList, by default it behaves like a DropdownList */
     .setPosition(100, 100)
     .setSize(200, 100)
     .setType(ScrollableList.LIST) // currently supported DROPDOWN and LIST

my intention is something similar to:


as if I had manually selected the second item.

I thank you in advance who can help me,

You can check out the doc. There are the list of all available functions:

Thanks! I saw that there is the method setValue i try now how does it work!

You also have the setItem() one if you know the name of the item and if I’m not mistaken.

Excuse my ignorance but i can’t find the method, isn’t in a list methods that appear with autocomplete code. There another way to use this methods?

Here they are:

setItems(java.util.List<java.lang.String> theItems) 
setItems(java.util.Map<java.lang.String,java.lang.Object> theItems) |
setItems(java.lang.String[] theItems)|

I never tried them though so it is really just a guess based on there name.

I’m currently using the setValue() function in one of my sketch and it works like a charm :slight_smile:

Thank you very much! i try it!

I try but not sure if it is possible. Add the following to cp5:


This sets the value display in the list when the list is close. Calling open forces to open the list. However, selecting it will be a bit trickier. Selection is tight to mouse events. You might need to override them. If this is your intention, you can look on previous posts related to overriding mouse events with controlP5 and see if you can find something that could use and try in your case.


    articoloCliente = listFileNames(pathDataSet + slash + clienti[clienteSelezionato]); // read a list of Files
    cp5.get(ScrollableList.class, "ARTICOLI").setLabel("ARTICOLI"); // reset the top label 
    cp5.get(ScrollableList.class, "ARTICOLI").setItems(articoloCliente); // change present list with <articoloCliente>
    cp5.get(ScrollableList.class, "ARTICOLI").open(); // force <ScrollableList> open

Solved! this solution works, but it should not be used inside of eventHandler because rise nullPointer exception.
Thanks kfrajer!