Adding a column of an array to a scrollable list with controlp5

I’m trying to make a program where you can type in a couple of strings, and I want a button to place all these strings in an array, and then add all the strings as a single item in a scrollable list. I just can’t figure out how to do it. I keep struggling with the ‘addItems’ and the ‘addItem’ syntax and I’m at the end of my line, can somebody help?

import controlP5.*;
import java.util.*;

ControlP5 cp5;
Textarea Output;
ScrollableList Recipelist;


//variables
int recipecount;
String[][] Input = new String[10][recipecount];

void setup() {
  size(1000, 565);
  
  PFont fontI = createFont("arial", 20);
  PFont fontO = createFont("arial", 10);
  
  cp5 = new ControlP5(this);
  
  //input boxes
  for(int i = 0; i < Input.length; i++) {
    cp5.addTextfield(str(i+1))
      .setPosition(25, 176 + 31*i)
      .setFocus(false)
      .setSize(700, 30)
      .setFont(fontI)
      .setColor(#000000)
      .setColorBackground(#FFFFFF)
      .setColorActive(#000000)
      .setColorCursor(#000000)
      .setAutoClear(false)
    ;
  }
  
  //output
  Output = cp5.addTextarea("Output")
              .setPosition(252, 2)
              .setSize(473, 99)
              .setFont(fontO)
              .setColor(0)
              .setColorBackground(255)
  ;
  Output.setText("");
  
  //generate button
  cp5.addButton("generate_command")
     .setPosition(251, 101)
     .setSize(475, 50)
     .setFont(fontI)
     .setLabel("generate command")
  ;
  
  //add button
  cp5.addButton("add_recipe")
     .setPosition(25, 500)
     .setSize(700, 50)
     .setFont(fontI)
     .setLabel("add recipe")
  ;
  
  //recipelist
  Recipelist = cp5.addScrollableList("recipelist")
                  .setPosition(750, 1)
                  .setSize(235, 560)
                  .setBarVisible(false)
                  .setItemHeight(20)
                  .setFont(fontO)
                  .setType(ScrollableList.LIST)
  ;
}

void draw() {
  background(255);
  fill(255);
  
  //crafting grid
  rect(1, 1, 50, 50);
  rect(51, 1, 50, 50);
  rect(101, 1, 50, 50);
  rect(1, 51, 50, 50);
  rect(51, 51, 50, 50);
  rect(101, 51, 50, 50);
  rect(1, 101, 50, 50);
  rect(51, 101, 50, 50);
  rect(101, 101, 50, 50);
  
  //crafting output
  rect(176, 51, 50, 50);
  
  //output border
  rect(251, 1, 474, 100);
  
  fill(0);
  textSize(30);
  textAlign(CENTER, CENTER);
  
  //crafting grid
  text("1", 25, 25);
  text("2", 75, 25);
  text("3", 125, 25);
  text("4", 25, 75);
  text("5", 75, 75);
  text("6", 125, 75);
  text("7", 25, 125);
  text("8", 75, 125);
  text("9", 125, 125);
  text("10", 200, 75);
  
  //input indication
  textSize(20);
  for (int i=0; i < Input.length; i++) {
    text(str(i+1), 10, 188 + 31*i);
  }
  
  
}

public void add_recipe() {
  for (int i = 0; i < Input.length; i++) {
    Input[i][recipecount] = cp5.get(Textfield.class,str(i+1)).getText();
  }
  
  
  //it's here where I get stuck
  Recipelist.addItems();
  
  
  
  recipecount++;
}
1 Like

Sorry, I’ve never used C5 before, but is Recipelist.addItems() supposed to take any parameters?

according to the documentation, Recipelist.addItems() requires a String[], List, or Map parameter, and Recipelist.addItem() requires a String and an Object, but I still don’t quite know what an object is.

1 Like

It is any Java Object – which is almost anything – to be “theValue” – the thing stored at that position and labeled by the String.

http://www.sojamo.de/libraries/controlP5/reference/controlP5/ScrollableList.html#addItem-java.lang.String-java.lang.Object-

Did you look at the Example on that documentation page?