Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Problem sizing a JFrame containing JInternal Frames.  RSS feed

 
Ranch Hand
Posts: 686
  • 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.
 
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: 686
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!