Stumped: Can't get ControlP5 DropdownList to run
in
Contributed Library Questions
•
11 months ago
I've been pulling my hair out on this one. I can't get the CP5 dropdown list to work. I keep getting "Cannot find class or type named "DropdownList" error. I've checked CP5 versions and have v.1.5.2 running with Processing 1.5.1. The other CP5 examples work fine, and I've been using the ControlP5 library for over a year on several projects. I've also tried Processing 2.0.5 to no avail. It's as if the DropdownList" control is not in this library. Any suggestions?
My next step is to move to the latest version of Processing to see if that helps, but I'm using a lot of serial comms to an Arduino and have not had good luck getting the 2x versions of Processing to work correctly. Maybe it's time to revisit that, but if someone knows how to get P1.5.1 to work with CP5 DropdownList I'd be very grateful
Here's the example code that throws the error:
- // controlP5 stuff
- import controlP5.*;
- ControlP5 controlP5;
- DropdownList p1;
- // define an array of images and the variable to select between them
- PImage[] images = new PImage[2]; // array of images
- int selectedImage; // the variable used to select the image to show on screen
- void setup() {
- size(400,400);
- // create the controlP5dropdownlist and give it the name you will use later, in this case ImageSelect
- controlP5 = new ControlP5(this);
- p1 = controlP5.addDropdownList("ImageSelect",width/2-50,100,100,120);
- customize(p1);
- // load images in setup
- images[0] = loadImage("image1.jpg"); // note: arrays start at zero!
- images[1] = loadImage("image2.jpg");
- }
- void draw() {
- background(128);
- image(images[selectedImage],0,0); // show the selected image
- }
- void customize(DropdownList ddl) {
- ddl.setBackgroundColor(color(190));
- ddl.setItemHeight(20);
- ddl.setBarHeight(15);
- ddl.captionLabel().set("Pulldown");
- ddl.captionLabel().style().marginTop = 3;
- ddl.captionLabel().style().marginLeft = 3;
- ddl.valueLabel().style().marginTop = 3;
- ddl.addItem("Image One",0); // give each item a value, in this example starting from zero
- ddl.addItem("Image Two",1);
- ddl.setColorBackground(color(60));
- ddl.setColorActive(color(255,128));
- }
- // this functions listens to events and can act upon it
- void controlEvent(ControlEvent theEvent) {
- // if the event is from a group, which is the case with the dropdownlist
- if (theEvent.isGroup()) {
- // if the name of the event is equal to ImageSelect (aka the name of our dropdownlist)
- if (theEvent.group().name() == "ImageSelect") {
- // then do stuff, in this case: set the variable selectedImage to the value associated
- // with the item from the dropdownlist (which in this case is either 0 or 1)
- selectedImage = int(theEvent.group().value());
- }
- } else if(theEvent.isController()) {
- // not used in this sketch, but has to be included
- }
- }
1