G4P Label Array Test for multiple windows

G4P Label Array Test
I’ve been trying to make a label array with the G4P Library in Processing 3. I’m having a problem with the “setText()” to an Array. Here’s the sketch. I’ve documented to problem area. Maybe someone can help. Run the sketch. Let me know what you think. Thanks everyone.

import g4p_controls.*;

GWindow window;
GLabel lbl1, lbl2;
GLabel[] lblArray= new GLabel[5];
String [] testArray= new String[5];

public void setup() {
  for(int i=0; i < 5; i++){
  testArray[i]=("["+i+"] "+ "test");
  window = GWindow.getWindow(this, "G4P Label Array Test", 210, 210, 500, 200, JAVA2D);
  window.addDrawHandler(this, "windowDraw");
  lbl1 = new GLabel(window, 10, 20, 200, 18);
  lbl1.setTextAlign(GAlign.LEFT, null);
  lbl2 = new GLabel(window, 10, 48, 200, 18);
  lbl2.setTextAlign(GAlign.LEFT, null);
  for(int i=0; i < 5; i++){
  lblArray[i] = new GLabel(window, 220, 20, 200, 20*i+1);
  lblArray[i].setTextAlign(GAlign.LEFT, null);
  for(int i=0; i < 5; i++){
  lblArray[i].setText("["+i+"] "+ testArray[i]); /*THIS LINE ONLY SETS THE LAST ELEMENT OF THE ARRAY AND NOT IN THE CORRECT SPOT*/
  println(lblArray[i]); //Look at he console output
public void draw() {

    lbl1.setText("["+ 1 +"] "+ "Test" );
    lbl2.setText("["+ 2 +"] "+ "Test");
public void windowDraw(PApplet app, GWinData data){
1 Like

All the labels are created in the same position the only difference is their heights. Try

lblArray[i] = new GLabel(window, 220, 20*i+1, 200, 20);
The parameters are x, y, w, h

1 Like

Thank you for responding so quickly. Looks like I had it backwards. Call
it digital dyslexia.
Thank again
Mark Cosmic