Resizing JFrame to match content pane size

Is there a way to resize JFrame so that it displays the whole size of the content pane or a JPanel added to it ?

Example:

I have a JFrame with a menu bar, and a single JPanel on the content pane. On the JPanel I paint an image. Now when I load an image that exceeds the frame bounds I want to resize the frame so that it shows the whole picture.

The problem is the frame resizing doesn't account for the height of the menu bar. I could use something like myFrame.setSize(imgWidth, imgHeight + menubarHeight), but I don't know how to retrieve the height of the menu bar, and besides, there must be a more elegant way to do this. Any tips?

[667 byte] By [Asfalotha] at [2007-11-26 14:56:13]
# 1
pack()
itchyscratchya at 2007-7-8 8:44:48 > top of Java-index,Desktop,Core GUI APIs...