title: Java swing: Multiline labels?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/685521/multiline-text-in-jlabel">Multiline text in JLabel</a>  </p>
  </blockquote>
  
  
  
  <p>I want to do this:</p>
  
  <pre><code>JLabel myLabel = new JLabel();
  myLabel.setText("This is\na multi-line string");
  </code></pre>
  
  <p>Currently this results in a label that displays</p>
  
  <pre><code>This isa multi-line string
  </code></pre>
  
  <p>I want it to do this instead:</p>
  
  <pre><code>This is
  a multi-line string
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p>Thank you</p>
  
  <hr>
  
  <p>EDIT: Implemented solution</p>
  
  <p>In body of method:</p>
  
  <pre><code>myLabel.setText(convertToMultiline("This is\na multi-line string"));
  </code></pre>
  
  <p>Helper method:</p>
  
  <pre><code>public static String convertToMultiline(String orig)
  {
      return "&lt;html&gt;" + orig.replaceAll("\n", "&lt;br&gt;");
  }
  </code></pre>