title: Java: Difference between the setPreferredSize() and setSize() methods in components
body: <p>What is the main difference between <code>setSize()</code> and <code>setPreferredSize()</code>. Sometimes I used <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html#setSize%28int,%20int%29" rel="noreferrer"><code>setSize()</code></a>, sometimes <a href="http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html#setPreferredSize%28java.awt.Dimension%29" rel="noreferrer"><code>setPreferredSize()</code></a>, sometimes one does what I want, sometimes the other.</p>
  <p>What call should I use for <code>JFrame</code>s and <code>JPanel</code>s?</p>