We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have the controlp5 textfield and a button. The button lets you select a folder and save a string path. How to i append the string to the textfield? Also i can get the list of subfolders from that directory. I managed to split them into a separate string array, however when i display them i get only the last one. How can i display all of them in a text(), but in a single strings? Here is the code.
import controlP5.*;
ControlP5 dirPath, dirButton;
String pathSelection = "";
String[] list = {};
File selection;
String path;
String[] dirSubfolders;
String[] singleFolder = {};
void setup(){
size(600, 600, P3D);
background(255);
PFont font = createFont("Calibri-48.vwl", 20);
dirPath = new ControlP5(this);
dirButton = new ControlP5(this);
dirPath.addTextfield("input")
.setPosition(20,20)
.setSize(200,30)
.setLabel("")
.setAutoClear(false)
.setFont(font)
.setFocus(true)
.setColor(color(255,0,0));
//OpenDirectory is the button ID. setLabel gives the name to be viewed
dirButton.addButton("OpenDirectory")
.setLabel("Open Directory")
.setPosition(250,25)
.updateSize();
}
void draw(){
background(0);
fill(255);
// get the text from the input textfield and display it on x & y location
// text(dirPath.get(Textfield.class, "input").getText(), 100, 100);
if(singleFolder == null){
println("empty");
} else {
for(int i=0; i < singleFolder.length; i++){
println(singleFolder[i]);
text(singleFolder[i], 100, 100);
}
}
}
// Button event directory selection
void OpenDirectory() {
println("Directory selection is pressed");
selectFolder("Select a folder to process:", "setDirectoryPath");
}
void setDirectoryPath(File pathSelection){
if(pathSelection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("Directory selected: " + pathSelection.getAbsolutePath());
// get the path to a string
path = pathSelection.getAbsolutePath();
// list the subfolders
dirSubfolders = pathSelection.list();
for(int i=0; i < dirSubfolders.length; i++){
// get the single string folder names
singleFolder = splitTokens(dirSubfolders[i], " ");
//check
//println(singleFolder);
}
}
}