Use controlP5 listBox to select string
in
Contributed Library Questions
•
3 years ago
I've this listbox (the file list.txt is a list of about 1000 names):
thanks
- import controlP5.*;
ControlP5 controlP5;
ListBox l;
ArrayList testoA = new ArrayList();
void setup( ) {
size(470, 295);
controlP5 = new ControlP5(this);
l = controlP5.addListBox("myList",20,40,80,240);
l.setItemHeight(15);
l.setBarHeight(15);
l.captionLabel().toUpperCase(true);
l.captionLabel().set("SELECT A NAME");
l.captionLabel().style().marginTop = 3;
l.valueLabel().style().marginTop = 3; // the +/- sign
//l.setBackgroundColor(color(100,0,0));
l.setColorBackground(color(255,128));
l.setColorActive(color(255,0,0,128));
String[] lines = loadStrings("list.txt");
for( int i = 0; i < lines.length; i++){
String[] tokens = lines[i].toLowerCase().split(" ");
for (int k = 0; k < tokens.length; k++){
testoA.add(tokens[k]);
l.addItem(tokens[k], k);
}
}
}
void controlEvent(ControlEvent theEvent) {
if (theEvent.isGroup()) {
// an event from a group e.g. scrollList
println(theEvent.group().value() +" from "+theEvent.group());
}
}
void draw(){
background(0);
text (tokens[ceil(theEvent.group().value())]);
}
thanks