Jump to content
  • Advertisement
Sign in to follow this  
Nicholas Kong

SetPreferredSize for a Frame in Java

This topic is 1854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The following code is in Java. I decided to create the dimensions for my frame object relative to the dimensions of an image I want displayed on the frame object which would mean I want the frame to scale with the image. However the frame could not show some of the bottom part of the image. So I needed to give the frame a bit more height by hard-coding 32 to it. While hard-coding works, it does not seem the right way to go about it in terms of efficiency. 
 
How come the setPreferredSize method does not scale with the image's dimensions?
 
Before: 
frame.setPreferredSize(new Dimension(gameMenuArt.getWidth(),gameMenuArt.getHeight()));
 
After:

frame.setPreferredSize(new Dimension(gameMenuArt.getWidth(),gameMenuArt.getHeight()+32));
Edited by warnexus

Share this post


Link to post
Share on other sites
Advertisement

I'm kinda rusty on Swing/AWT stuff right now but I think it may have to do with the preferred size taking in account the size of the title bar of the window (the one with the close, minimize and maximize buttons).

Share this post


Link to post
Share on other sites

I'm kinda rusty on Swing/AWT stuff right now but I think it may have to do with the preferred size taking in account the size of the title bar of the window (the one with the close, minimize and maximize buttons).

Oh! I never thought about it like that. You got a point there!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!