aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes getInsets() and Frames Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getInsets() and Frames" Watch "getInsets() and Frames" New topic

getInsets() and Frames

Diana Liah

Joined: Jan 11, 2002
Posts: 2
Has anyone else had a problem getting correct values for border sizes when using getInsets() inside Frames? I have a Frame to which I am adding a container, but despite my use of getInsets().top (etc.) the component is still partially obscured when the Frame is shown.
I have the following code to try to set the Frame to its correct size:
setSize(getInsets().left + cont.getSize().width + getInsets().right, getInsets().top + cont.getSize().height + getInsets().bottom);
It does not seem to matter whether this code is placed within the Frame's constuctor or in a method that is called afterwards. I have tried printing the insets to the standard output, and they all come out to be "0" for some reason.
Can anyone explain this?
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
I made a little test with an JFrame, which holds only one button. When I asked for the Insets during initializint the JFrame, I got the same result like you, but on a Buttonclick I got a different result. I think, it is only possible to ask for those values if a component is really visible, I mean if you can see it.
And welcome to the JavaRanch.

Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

If you read the APIs for the Frame class, you will find this interesting little tidbit...

The size of the frame includes any area designated for the border. The dimensions of the border area may be obtained using the getInsets method, however, since these dimensions are platform-dependent, a valid insets value cannot be obtained until the frame is made displayable by either calling pack or show. Since the border area is included in the overall size of the frame, the border effectively obscures a portion of the frame, constraining the area available for rendering and/or displaying subcomponents to the rectangle which has an upper-left corner location of (insets.left,, and has a size of width - (insets.left + insets.right) by height - ( + insets.bottom).

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Diana Liah

Joined: Jan 11, 2002
Posts: 2
Rene and Nate,
Thank you for your help. I used pack() before setting the size, and it works perfectly.
I agree. Here's the link:
subject: getInsets() and Frames
Similar Threads
Resizing frame when positioning the mouse in the frame
jsp forwarding to a target frame