title: Break up long line of text in Java or Scala
body: <p>I have a <code>String longLineOfWords</code>, that I want to break up into several lines (<code>List&lt;String&gt; severalShortLinesOfWords</code>, or similar).</p>
  
  <p>Whether a line is too long, and should therefore be broken up, is determined by the following function:</p>
  
  <pre><code>private def isLineTooLong(line: String): Boolean = {
    val bufferedImage = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB)
    val graphics = bufferedImage.getGraphics
  
    val metrics = graphics.getFontMetrics(font)
  
    metrics.stringWidth(line) &gt; imgWidth
  }
  </code></pre>
  
  <p>This is difficult programming for me. Can someone help me?</p>