This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem sizing a JFrame containing JInternal Frames.

 
Fred Hamilton
Ranch Hand
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 684
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic