Hi all,
I'm currently working on centering my main frame, and have a question regarding thread safety in swing. Is it safe to make a call to center the frame between the pack() and setVisible() methods. According to the Sun Tutorial...
The components in the GUI are realized by the pack call.
Immediately afterward, the components in the GUI are shown with the setVisible (or show) call. Technically, the setVisible call is unsafe because the components have already been realized by the pack call. However, because the program doesn't already have a visible GUI, it's exceedingly unlikely that a paint request will occur before setVisible returns.
If I write my code as follows:-
frame.pack()
frame.setVsible(true)
frame.setLocationRelativeTo(null)
Then the window will first appear in the top corner, then move to the center which looks ugly
re-ordering the code to
frame.pack()
frame.setLocationRelativeTo(null)
frame.setVisible(true)
will get rid of the window movement glitch, but is this an unsafe way of doing it?
Any comments, thoughts, feedback gratefully accepted.
Thanks,
Paul
I'm currently working on centering my main frame, and have a question regarding thread safety in swing. Is it safe to make a call to center the frame between the pack() and setVisible() methods. According to the Sun Tutorial...
The components in the GUI are realized by the pack call.
Immediately afterward, the components in the GUI are shown with the setVisible (or show) call. Technically, the setVisible call is unsafe because the components have already been realized by the pack call. However, because the program doesn't already have a visible GUI, it's exceedingly unlikely that a paint request will occur before setVisible returns.
If I write my code as follows:-
frame.pack()
frame.setVsible(true)
frame.setLocationRelativeTo(null)
Then the window will first appear in the top corner, then move to the center which looks ugly
re-ordering the code to
frame.pack()
frame.setLocationRelativeTo(null)
frame.setVisible(true)
will get rid of the window movement glitch, but is this an unsafe way of doing it?
Any comments, thoughts, feedback gratefully accepted.
Thanks,
Paul