# G4P Label Array Test for multiple windows

**URL:** <https://discourse.processing.org/t/g4p-label-array-test-for-multiple-windows/4908>\
**Category:** Libraries\
**Created:** [October 26, 2018, 7:53pm UTC](https://discourse.processing.org/t/g4p-label-array-test-for-multiple-windows/4908 "2018-10-26T19:53:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![markcosmic](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@markcosmic](https://discourse.processing.org/u/markcosmic)\
**Post date:** [October 26, 2018, 7:53pm UTC](https://discourse.processing.org/t/g4p-label-array-test-for-multiple-windows/4908/1 "2018-10-26T19:53:12Z")

</div>

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.

```auto
import g4p_controls.*;

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

public void setup() {
  size(100,300);
  for(int i=0; i < 5; i++){
  testArray[i]=("["+i+"] "+ "test");
  println(testArray[i]);
  }
  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);
  lbl1.setOpaque(true);
  lbl2 = new GLabel(window, 10, 48, 200, 18);
  lbl2.setTextAlign(GAlign.LEFT, null);
  lbl2.setOpaque(true);
  for(int i=0; i < 5; i++){
  lblArray[i] = new GLabel(window, 220, 20, 200, 20*i+1);
  lblArray[i].setTextAlign(GAlign.LEFT, null);
  lblArray[i].setOpaque(true);
  }
  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){
    app.background(0);
}

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [October 26, 2018, 9:58pm UTC](https://discourse.processing.org/t/g4p-label-array-test-for-multiple-windows/4908/2 "2018-10-26T21:58:20Z")

</div>

> [@markcosmic](#):
>
> lblArray[i] = new GLabel(window, 220, 20, 200, 20\*i+1);

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

---

<div class="post-metadata">

**Author:** ![markcosmic](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@markcosmic](https://discourse.processing.org/u/markcosmic)\
**Post date:** [October 27, 2018, 4:20am UTC](https://discourse.processing.org/t/g4p-label-array-test-for-multiple-windows/4908/3 "2018-10-27T04:20:11Z")

</div>

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