Re: Refreshing JDialog

From: John McGrath (ng_at_jpmcgrath.net)
Date: 11/22/04


Date: Mon, 22 Nov 2004 06:32:35 GMT

On 11/21/2004 at 8:28:00 PM, Bruce Stemplewski wrote:

> Thanks what I don't understand is that I close the second dialog box
> before I start the long process. Why isn't the first dialog repainted?
> Is it because the button event from the first dialog has not been exited?

Yes, exactly. No events are processed while your process is running.

Events are processed / dispatched by the event dispatch thread, which runs
a simple loop that just pulls an event from the event queue and dispatches
it. Paint events are placed on this queue, and they are dispatched by
calling your component's paint() method. Action events created when one
of your component's buttons are pushed are also placed on this queue, and
they are dispatched by calling your listener's actionPerformed() method.
The obvious implication of this is that no painting will occur until your
actionPerformed() method returns.
        
Modal dialogs are different - basically what happens there is that, when a
modal dialog is shown, it starts a new event loop, inside the setVisible()
method. That is why you do not need to return from your actionPerformed()
method before the modal dialog can be painted.

There is some very good material covering this in The Java Tutorial on the
Sun web site (http://java.sun.com/docs/books/tutorial/index.html). I
would definitely recommend that you take a look at this, especially the
trails, "Essential Java Classes" and "Creating a GUI with JFC/Swing".

-- 
Regards,
John McGrath