tags:

views:

61

answers:

1

Hi,

I'm setting a JFrame size with myFrame.setSize(Xsize,Ysize), but it gives me a problem : this doesn't define the usable space in the frame but the whole frame's size (it include the Windows Manager frame size, which isn't always the same). Is there any way to define the JFrame size by defining the usable space size ?

+4  A: 

Usually the best method is to setPreferredSize() on the contents of the frame and then call pack().

If that is not possible then I think calling getInsets() on the Window will grab the size of the window manager frame as long as the frame is completely visible (you may need to use a listener and wait until a windowOpened() event). I haven't actually tried this on X but it definitely works on Windows. The downside of that approach is that the frame appears and then resizes. You could start it off screen and then move it to a visible location once you have the insets.

Russ Hayward
I think you can avoid seeing the resize by calling pack() prior to calling setVisible(true)
Joshua McKinnon
the use of getInsets() did the trick, thanks you very much !
Cheshire