title: Simple Program Help - How To Display Multiple Lines of Text in JTextAreas From An Array List?
body: <p>I'm trying to write a program that stores 5 song titles in an ArrayList "cdNames", and outputs them in a text area, one title per line, 5 lines total.   </p>
  
  <p>Im using the <code>.setText</code> method and a <code>for loop</code> to try to pull the 5 elements from the ArrayList to display the 5 song titles, without having to explicitly write each title out. </p>
  
  <p><strong>What follows is the portion of my code that deals with the JTextArea:</strong></p>
  
  <pre><code>private void btnDisplayMouseClicked(java.awt.event.MouseEvent evt) {
  for (int i = 0; i&lt;cdNames.size();i++){
  txtOutputBox.setText(cdNames.get(i));
  </code></pre>
  
  <p>The problem lies in that the only thing displayed in the text area is the last element in the array list.</p>
  
  <p>Index # 4 i.e. The Rolling Stones - Gimme Shelter.</p>
  
  <p>I believe the setText method is overwriting the previous elements and stopping at the last, instead of printing out each title on a new line.</p>
  
  <p>I think my troubles lie in my insufficient knowledge of how text areas display text.</p>
  
  <p>I'm new to java, so please try to answer my question simply if possible.</p>