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?
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.
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).
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Jan 11, 2002
Rene and Nate, Thank you for your help. I used pack() before setting the size, and it works perfectly. Diana
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com