> That shouldn't be necessary. You are explicitly allowed to call Swing
methods from any thread until the component is realized. The problem
is thread safety and calls to paint() from the event loop, but the
component won't be painted until it's shown.
Yes and no. For example, Containers are not synchronized, so adding/
removing Components from multiple threads has concurrency issues with
accessing the underlying collection. As for the code fragment I
posted, realization occurs during pack(), so pack() and show() must
be done on the Swing thread. Constructing the object could be done in-
line in main first:
public static void main (String[] args) {
final MyMainFrame frame = new MyMainFrame();
SwingUtilities.invokeLater (new Runnable() {
public void run() {
frame.pack();
frame.show();
}
});
}