controlP5 – Get selected dropdown item text as string?

UPDATE-
Needed to read some Java docs on how to use Map– here is my solution:

cwDropdown.getItem((int)val).get("text")

Though it returns as an Object rather than a String…


Hi-

I’m having a heck of a time getting the string of the selected item in a DropdownList or ScrollableList within controlP5.

On my selection event, I can’t seem to figure out what will pull the selected item’s TEXT or LABEL as a string.

/// Change colorway
   
val = theEvent.getController().getValue();

if (theEvent.getController().getName()== guiColorwayString) {

  // Displays something incorrect- possibly the initial value of the DropdownList?
  println(".getText() : " + theEvent.getController().getValueLabel().getText()); 
  
  // Displays "...valuelabel (255,255,255), name=WHITE on WHITE, text=WHITE on WHITE..." in Console but can't figure out how to "get" `name` or `text` as a string?
  println("cwDropdown: " + cwDropdown.getItem((int)val)); 

}

Any help would be greatly appreciated!

Did you see the example

http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5dropdownList/ControlP5dropdownList.pde

http://www.sojamo.de/libraries/controlP5

Just testing this code and it doesn’t seem to work anymore.

I get a bunch of errors not just the one.

The function setIndex(int) does not exist.