JFrame - intermittently loaded as small window
I've got a JFrame that I use as my app's main window. It is displayed at startup.
Occasionally (not always but often enough that it is definitely a problem), the window will come up as nothing but the title bar (in other words, the title on the left side and the min/max/close buttons on the right). The title bar is created so that it is not very wide (so that a title of "Title" would display as "T...").
When I construct the JFrame, I do the following:
setExtendedState(Frame.MAXIMIZED_BOTH);
setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
setResizable(false);
Any ideas as to why in the world this would *sometimes* happen but usually I have no problems at all?
It seems to happen most-often the first time the application is started. If I then exit the app and try again it will work fine.
I'm using JDK 1.5.0_04-b05
Thanks!
[909 byte] By [
matt_apta] at [2007-10-3 3:39:06]

Hey Matt,
Well since you don't want your frame to be resizable, why don't you just use the setSize method instead of setPreferredSize.
Maybe that will solve the problem.
Also, when do you call setVisible() to show your frame?
After all those lines of code you posted I hope ;-) , if not, that might be your problem.
And why do you need to call setExtendedState(Frame.MAXIMIZED_BOTH) if you later on set the frame size to the size of the screen anyways... seems redundant.
Let me know if it works,
-Mike
> Well since you don't want your frame to be resizable,
> why don't you just use the setSize method instead of
> setPreferredSize.
>
> Maybe that will solve the problem.
So far so good, but I'm going to withhold final judgement until I get some more usage out of it ;)Any ideas as to why this would be the case? I'd like to understand why my method was wrong.
> Also, when do you call setVisible() to show your
> frame?
> After all those lines of code you posted I hope ;-) ,
> if not, that might be your problem.
Yes, setVisible(true) was called after those lines.
Thanks!