title: Changing preferred size of a Swing component
body: <p>I have a swing component where the ideal size of the component will <strong>vary based on the content</strong> that is is currently being displayed (which happens in this case to be an image). </p>
  
  <p>I'd like this preferred size to change when the content is changed, and also allow the layout to be changed (for example, if the component is being used inside a JScrollPane then the scroll extents would change to fit the size of the component).</p>
  
  <p>What is the canonical way to do this in Swing ?</p>