why sun recommends this way

From: Madhur Ahuja (ef_at_df.com)
Date: 08/24/04

  • Next message: John C. Bollinger: "Re: How can I trap UI events non-intrusively?"
    Date: Tue, 24 Aug 2004 03:32:21 +0530
    
    

    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.

    --
    Winners dont do different things, they do things differently.
    Madhur Ahuja
    India
    Homepage : http://madhur.netfirms.com
    Email    : madhur<underscore>ahuja<at>yahoo<dot>com
    

  • Next message: John C. Bollinger: "Re: How can I trap UI events non-intrusively?"

    Relevant Pages

    • Re: why sun recommends this way
      ... > public void run{ ... It might look daunting, but ... Usually you create GUI in the main thread. ... So the app is safe ...
      (comp.lang.java.gui)
    • Re: New Swing Window Not Drawn
      ... Instead of setting aFlag, you should simple fire an event on the EDT. ... otherwise your doExtensiveThings is going to block ... Also, as I've experimented, I've found that if I put any GUI updates within ... public void run{ ...
      (comp.lang.java.programmer)
    • How to convert GUI components graphics to int[]or byte[]?
      ... Has anyone ran into the problem of trying to get a GUI component's graphics converted into an array of ints? ... private TestGraphicPanel testPanel; ... public void windowDeactivated ...
      (comp.lang.java.gui)
    • Re: busy cursor
      ... What I want to do is display an hour glass while the application is performing its calculations. ... Problem is that if I hover my cursor over another window and then back over the original window, ... public void actionPerformed ... say I have the main class that constructs a gui. ...
      (comp.lang.java.gui)
    • Re: Problem to input more numbers when thread is running
      ... The problem I have is that while I am doing the pause and the actual calculation in my thread I cannot input more numbers in the gui and hence start more calculation threads. ... public void run{ ...
      (comp.lang.java.help)