title: How can I clip strings in Java2D and add ... in the end?
body: <p>I'm trying to print Invoices in a Java Swing applications. I do that by extending <code>Printable</code> and implement the method <code>public int print(Graphics g, PageFormat pf, int page)</code>.</p>
  
  <p>I would like to draw strings in columns, and when the string is to long I want to clip it and let it end with "...". How can I measure the string and clip it at the right position?</p>
  
  <p>Some of my code:</p>
  
  <pre><code>Font headline = new Font("Times New Roman", Font.BOLD, 14);
  g2d.setFont(headline);
  FontMetrics metrics = g2d.getFontMetrics(headline);
  g2d.drawString(myString, 0, 20);
  </code></pre>
  
  <p>I.e How can I limit <code>myString</code> to be max 120px?</p>
  
  <p>I could use <code>metrics.stringWidth(myString)</code>, but I don't get the position where I have to clip the string.</p>
  
  <p>Expected results could be:</p>
  
  <pre><code>A longer string that exc...
  A shorter string.
  Another long string, but OK
  </code></pre>