Re: why sun recommends this way
From: Adam (NOTFORSPAM.a_szczeblewski_at_poczta.onet.pl)
Date: 08/24/04
- Next message: bernd_no_junk_at_hotmail.com: "maximize JFrame again and again (OS X)"
- Previous message: VisionSet: "Re: JDialog, Icon, Windows"
- In reply to: Madhur Ahuja: "why sun recommends this way"
- Next in thread: xarax: "Re: why sun recommends this way"
- Reply: xarax: "Re: why sun recommends this way"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 24 Aug 2004 08:32:11 +0200
"Madhur Ahuja" <ef@df.com> wrote in message
news:2ov7edFeps6mU2@uni-berlin.de...
>
> Hello
>
> The final bit of code in HelloWorldSwing--and in all of our
examples--looks
> like this:
> javax.swing.SwingUtilities.invokeLater(new Runnable() {
> public void run() {
> /* create and show the GUI */
> }
> });
>
> You can copy this code and use it as-is. It might look daunting, but
we
> recommend it because it ensures that the GUI won't have a
thread-safety
> problem that could break the UI before it even appears onscreen.
>
> Can anybody explain me, why this is the preferred method of creating
GUI
> program.
Usually you create GUI in the main thread. On the way the
EventDispatchThread
can be started (when you show() the first of your frames) and you have
two threads working on the same resource - GUI. Swing is not thread
safe,
assumes accessing it's objects from within one thread.
The code presented allows moving the GUI-creation from the main thread
to the EDT - so only one thread works with GUI. So the app is safe
again.
HTH,
Adam
- Next message: bernd_no_junk_at_hotmail.com: "maximize JFrame again and again (OS X)"
- Previous message: VisionSet: "Re: JDialog, Icon, Windows"
- In reply to: Madhur Ahuja: "why sun recommends this way"
- Next in thread: xarax: "Re: why sun recommends this way"
- Reply: xarax: "Re: why sun recommends this way"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|