Question about GDropList in G4P library

I’m having trouble using a droplist. I’ve looked at the examples and read through the user guides on the web site, but I can’t see what I’m doing wrong. In all the examples I’ve tried, the droplist collapses after the user makes a selection, but when I run the code below, the list never collapses (although the selection is returned to the program). What am I doing wrong?

import g4p_controls.*;

String dest[] = {"Selection 1","Selection 2","Selection 3"};
GDropList dropList1; 

public void setup() {
  size(600,400,JAVA2D);
  G4P.messagesEnabled(false);
  G4P.setMouseOverEnabled(false);
  dropList1 = new GDropList(this, 20, 20, 120, 200, 10);
  dropList1.addEventHandler(this, "dropListHandler");
  dropList1.setItems(dest,0);
}

public void draw() {
}

public void dropListHandler (GDropList source, GEvent event) {
  println("dropList >> GEvent." + event + " @ " + millis());
  println("selected text = "+source.getSelectedText());
}
1 Like

@quark I’m not sure if this is a bug or just something I don’t understand, but I discovered that if I added a line to the draw() method, it works. Here’s what the draw() method looks like now:

public void draw() {
  background(230);
}

That’s the only change I made. Is this expected behaviour?

Thanks.

This is not a bug, G4P requires you to use either background() or some other command to remove the previous control image for every frame.

2 Likes