Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying an ArrayList?

Tags:

java

arrays

list

ArrayList <String> cdcollection = new ArrayList();

private void initButtonActionPerformed(java.awt.event.ActionEvent evt) {
    Collections.addAll(cdcollection, "small", "mayre", "brown", "evner", "rain" );
    initButton.setEnabled(false);

}

private void displayButtonActionPerformed(java.awt.event.ActionEvent evt) {

          for (int i = 0; i < cdcollection.size(); i++)  {
          mainTextArea.setText(cdcollection.get(i));
    }
}

private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {
    cdcollection.add(cdtitleInput.getText());
}

private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {
    cdcollection.remove(cdcollection.size()-1);
}

When I run this and click the display button only the last cd title (rain) appears... How can I get all five cd titles to appear each on one line?

like image 258
May Avatar asked May 20 '26 11:05

May


1 Answers

Use Append() instead of setText()

like image 78
OmniOwl Avatar answered May 22 '26 01:05

OmniOwl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!