Ok, so some background info before I get into my dilemma: I’m writing a game in Swing (stupid move, I know, however it’s working well and I don’t feel like moving it AWT). It’s contained in a JFrame window (not fullscreen). I’m using Java 1.5 on Windows XP.
Now to my dilemma:
I have an option to resize the window to either a larger or a smaller size. When I recieve the event to resize the window (I generate it through a custom UI), I use the code:
frame.setSize(newWidth, newHeight);
setSize(newWidth, newHeight);
repaint();
Where frame = top level JFrame for my game.
This code has a tendency to not work.
It resizes the window, however does not paint/resize the component (I’m not sure which, only the part of the component which was visible before is painted after being resized). I can force it to display the component/my game by resizing the window with the cursor, or by minimizing/restoring it.
When I initally create the window I use the following code:
f.setVisible(true);
Insets i = f.getInsets(); //Get the window borders
f.setSize(Preferences.WIDTH + i.left + i.right, Preferences.HEIGHT + i.top + i.bottom); //Set to the size so that the entire playfield is shown
I have to show the window before I determine it’s size so I can get the Insets (instead of useless garbage). When I first start up my game, the window is resized to the proper size, however the component inside isn’t.
I have tried adding a frame.pack() in the first code segment before the repaint() (I have also tried using frame.repaint()), however the pack() statement completely discards the size I give it and sets it to a little box (I think the minimum window size in XP).
I have looked/tried to use setMinimumSize() and setMaximumSize(), and wasn’t able to get any results (well, actually, lack of change would be more accurate… 
If someone could tell me what I’ve missed here, I would greatly appreciate it.
Also, I tried this exact code on 1.6, and it worked perfectly. The javadocs mention no change in those methods from 1.5 to 1.6 (at least not that I could find).