aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem sizing a JFrame containing JInternal Frames. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem sizing a JFrame containing JInternal Frames." Watch "Problem sizing a JFrame containing JInternal Frames." New topic
Author

Problem sizing a JFrame containing JInternal Frames.

Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
OK, I am developing a Desktop GUI for a gaming application. The high-level container is a JFrame, this is my game room.
Within the JFrame there are one or more JInternalFrame, these are tables. Tables are added to a JDesktopPane, and the JDesktopPane is set as the contentPane of the JFrame. finally, the GUI for each table will be identical, and is built upon a JPanel which is set as the content pane of each JInternalFrame.

Below is a prototype of the GUI, it is entirely self contained and can be compiled and run as is.



The problem is, when I run the application, the JFrame displays as only the title bar, it can be expanded by dragging the lower border, but obviously that is not a solution. Notice that the JInternalFrame gets sized properly. I would have thought that the fact that table1 is sized properly, combined with the fact that the room is packed in main(), would mean that the room display just large enough to contain the table, but I guess this is not the case.

I suppose I am overlooking something obvious, but I can't see what it is.

Thank you.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
It would seem to me that the JDesktopPane doesn't set its preferredSize based on its contents. If you look at the code from Sun tutorial on using internal frames, you'll see that they size the JFrame using Toolkit to get the screen size.

The tutorial can be found here: How to use Internal Frames
and you can download the sample code here: Internal Frame Demo Project
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
pete stein wrote:It would seem to me that the JDesktopPane doesn't set its preferredSize based on its contents.

...



Well yeah, I would say so too

Anyways, I just tried a setPreferredSize on the JDesktopPane and it worked, so I guess I can live with that.

Interestingly enough, I initially tried to add the JInternalFrame directly to the JFrame, and the JFrame sized properly, but I could not for the life of me prevent the JInternalFrame from being resized along with the JFrame, even when the constructor of the internal frame specified no resizing. Using JDesktopPane solved that problem, but introduced the one that started out this thread. ANyways, all's well that ends well.

Thanks again Pete. regards.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem sizing a JFrame containing JInternal Frames.