Stephan van Hulst wrote:Swing uses a special Event Dispatch Thread that interacts with the OS...
Stephan van Hulst wrote:
Swing uses a special Event Dispatch Thread that interacts with the OS to catch events and draw components on the screen. Running just the code that sets up your interface will not do anything special to let it react to events and repaint it.
You don't need to know in-depth about multi-threading to be able to write Swing applications, but it's definitely recommended and even required for more complex scenarios.
I confused myself, Campbell is right of course. Problems you may experience from running GUI related code in a thread other than that EDT are likely caused because of synchronization problems.
when I add JTextField to the frame, all I get is a blank frame.
Campbell Ritchie wrote:And the API tells you clearly that Swing is not thread safe.
That is one of the possibilities I mentioned: nothing unusual. But it is as well to learn the correct method as soon as possible, rather than saying, “Nothing went wrong last time I did it like that.”
Rob Camick wrote:. . . 99% of the time on a simple example like this it doesn't matter if you use the SwingUtilities.invokeLater(...), the code will work. . . .