Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JFrame to fit JPanel, pack method not working

843804Dec 5 2004 — edited Dec 30 2004
I'm creating a JFrame with a single JPanel in it containg an image. I set the JPanel size to be the height and width of the image, and then tried using the pack() method on JFrame to make the JFrame fit the image. When I run the program though, the JFrame ends up being at the minimum size. I've checked and made sure that the panel is in fact the size of the image, so setting the panel size is not the problem.

I've been able to hack around this by manually determining the number of pixels are used by the borders in the Windows XP look and feel, and setting the JFrame size as the image size plus the border size, but this just doesn't sit well with me, and will probably give me problems when I run my application on other operating systems.

Any clues on what I need to do? Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 27 2005
Added on Dec 5 2004
8 comments
834 views