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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getInsets() and Frames" Watch "getInsets() and Frames" New topic
Author

getInsets() and Frames

Diana Liah
Greenhorn

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
Hi,
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.

Rene
Nathan Pruett
Bartender

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, insets.top), and has a size of width - (insets.left + insets.right) by height - (insets.top + insets.bottom).


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

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.
Diana
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getInsets() and Frames