title: JLabel: setPreferredSize manually but getPreferredSize after setText
body: <p>i want to set the size of a <code>JLabel</code> to a specific (minimum) size via <code>setPreferredSize()</code>.
  If the text inside the <code>JLabel</code> doesn't fit anymore, the <code>JLabel</code> should grow.</p>
  
  <p>The problem now is:</p>
  
  <ul>
  <li>after <code>label.setPreferredSize(new Dimension(50,20));</code></li>
  <li>i do <code>setText("new long text");</code> but the size won't change</li>
  </ul>
  
  <pre class="lang-java prettyprint-override"><code>import java.awt.Dimension;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.SwingUtilities;
  import javax.swing.WindowConstants;
  
  public class LabelTest
  {
      public static void createWindow()
      {
          JFrame frame = new JFrame();
  
          JLabel label = new JLabel("Text");
          System.out.println(label.getPreferredSize().width); // 25
          label.setText("New long text");
          System.out.println(label.getPreferredSize().width); // 77 - JLabel grows as expected
  
          label.setText("Text");
          System.out.println(label.getPreferredSize().width); // 25
          label.setPreferredSize(new Dimension(50, 20));
          System.out.println(label.getPreferredSize().width); // 50 - JLabel grows to given size as expected
          label.setText("New long text");
          System.out.println(label.getPreferredSize().width); // 50 - it should be 77 again
  
          frame.add(label);
          frame.setPreferredSize(new Dimension(200, 100));
          frame.pack();
          frame.setVisible(true);
          frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      }
  
  
      public static void main(String[] args)
      {
          SwingUtilities.invokeLater(new Runnable()
          {
              public void run()
              {
                  createWindow();
              }
          });
      }
  }
  </code></pre>
  
  <p>So i need a solution to get the new preferred size when a text is set after i already set the preferred size manually.</p>
  
  <p>If you need more information just ask.</p>
  
  <p>Thanks in advance!</p>