jFrame.setSize(1024, 768); doesnt do 1024, 768! (?)
Hello fellows,
so its an OS dependent setting I think.
I have a background image in my JFrame, which is 100% 1024x768px.
If I am setting myJFrame.setsize(1024,768); not the whole image is visualised.. on the right edge and the bottom edge something is missing from my background image. (not more than 50px).
My guess is that 1024x768 is for the WHOLE JFrame, which includes the OS specific menu , title stuff.
If I am right how can I OS independent set the really visible and usable area to 1024x768?
Thanks in advance!
SA.
ahh... the pack() stuff was it!So, I really need to review all the size stuff (minimum, maximimun, size, preferredSize, etc..). Im a bit confused at the moment... but thanks anyway!SA.
> job.[code]frame.getContentPane.setPreferredSize( new
> Dimension(1024, 768) );
this is somewhat tangential to the original question... I haven't found any hard documentation whether the preferred size of a JFrame means the bounding size or just the size of its content pane. However, considering how other Swing components are implemented, it's reasonable to assume that setting the preferred size of a jframe will set it's outer dimention (bounding box). This is also supported by list item #1 from http://java.sun.com/docs/books/tutorial/uiswing/layout/howLayoutWorks.html. So if I wanted to explicately set the content pane to be of a certain size, I'd still have to account for the frame's menu and decorations (i.e. insets).
> My guess is that 1024x768 is for the WHOLE JFrame, which includes the OS specific menu , title stuff.
Yes, I'm 99.44% certain that this is the case.
> If I am right how can I OS independent set the really visible and usable area to 1024x768?
See camickr's reply (though he forgot parens, you get the idea)
Also, you might want a little "breathing room" for your app, so that it isn't chopped off on the edges:
1) Instead of 1024x768, subtract 2 pixels in each dimension (1022x766), and place it with a 1 pixel offset, to ensure that the edges of the frame are visible all the way around.
2) If on Windows, allow for about 30 or 40 pixels for the Windows taskbar, keeping in mind that most users keep it on the bottom, but some place it to the side (Heathens!), so maybe your final target Dimension is somewhere around (984x728)
3) Laptops will have funny Dimensions (same width, shorter height)
> So if I wanted to explicately set the content pane to be of a certain
> size, I'd still have to account for the frame's menu and decorations (i.e. insets).
I'm not sure I understand the confusion with my suggestion although I must admit my example was wrong in more ways than one. The actual code would be:
JPanel contentPane = (JPanel)frame.getContentPane();
contentPane.setPreferredSize( new Dimension(?, ?) );
frame.pack();
frame.setVisible( true );
System.out.println( frame.getSize() );
System.out.println( frame.getInsets() );
System.out.println( frame.getContentPane().getSize() );
The pack() method will worry about the actual size of the frame incorporating the insets.
Note: frame.setPreferredSize() is a new method in JDK1.5 (which I don't use), but I assume its equivalent to frame.setSize() in that the actual size of the content pane will be smaller based on the insets of the frame.