I have a swing component where the ideal size of the component will vary based on the content that is is currently being displayed (which happens in this case to be an image).
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).
What is the canonical way to do this in Swing ?