How would I use
for (int j = 0; j < song.size(); j++) {
outputBox.setText(j + ": " + song.get(j));
}
To display all the items in an array, rather than replacing them as it goes and leaving the last one? Using java.
How would I use
for (int j = 0; j < song.size(); j++) {
outputBox.setText(j + ": " + song.get(j));
}
To display all the items in an array, rather than replacing them as it goes and leaving the last one? Using java.
You should use JTextArea#append
...
outputBox.append(j + ": " + song.get(j));
But you'll probably also want to include a new line character at the end
outputBox.append(j + ": " + song.get(j) + "/n");
See JTextArea#append
and How to Use Text Areas for more details
It may be more efficient to use a StringBuilder
and the set the text of the text area after the fact
StringBuilder sb = StringBuilder(128);
for (int j = 0; j < song.size(); j++) {
sb.append(j).
append(":").
append(song.get(j)).
append("/n");
}
outputBox.setText(sb.toString());
Just guessing but...
String oldText = outputBox.getText();
outputBox.setText(oldText + j + ": " + song.get(j));