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