Loading...
Logo
Processing Forum
Is there a way to add an listener to a listbox that will be fired if I select an item. Note I dont use the listbox in the PApplet main class. On a textfield I can add listener with addListener  but listbox dont have this method. Also controlEvent() seems only to work in the PApplet class.

Replies(1)

OK found a way by myself. You can add a listener to the controlP5 base so you can check every event by yourself:

                listBox = controlP5.addListBox("listbox", 70, 50, 100, 100);

listBox.actAsPulldownMenu(true);

listBox.setId(1);

controlP5.addListener(new ControlListener() {


@Override

public void controlEvent(ControlEvent arg0) {

if (arg0.isGroup()) {


if (arg0.group().id() == 1) {

PApplet.println(listBox.value());

}

}


}

});