title: How to auto resize JFrame according to content
body: <p>I have created a custom <code>JPanel</code> that displays images (lets call it <code>MyPanel</code>), I have added this to <code>JFrame</code>'s contentPane.</p>
  
  <p>I want <code>JFrame</code> to be resized automatically to fit the <code>MyPanel</code> when image changes.</p>
  
  <p>It looks like I need to call <code>frame.pack()</code> to do this. Calling <code>pack()</code> from <code>MyPanel</code> increases coupling so I don't want to do that.</p>
  
  <p>To solve the issue I extended <code>JFrame</code> (lets call it <code>MyFrame</code>) and made <code>MyFrame</code> observer, and <code>MyPanel</code> observable. Whenever the image <code>MyPanel</code> is displaying changes it notifies the listeners, <code>MyFrame</code> for this instance. And then <code>MyFrame</code> calls <code>pack()</code> when it gets the notification.</p>
  
  <p>Is there a smoother way of resizing <code>JFrame</code> according to its content?</p>