• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI Question - Centering Frame and Thread safety

Paul Moon
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:-
Then the window will first appear in the top corner, then move to the center which looks ugly
re-ordering the code to
will get rid of the window movement glitch, but is this an unsafe way of doing it?
Any comments, thoughts, feedback gratefully accepted.
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!