JFrame got no chance to be repained due to synchonized function?

I have a JFrame window,click one button, it will invoke a syncronized function which triggers another program (eg. taskProgram).The taskProgram is a little time-consuming and it will show another taskMonitor window.

The taskMonitor window will overlap the first JFrame window. Then i try to move away the taskMonitor window, and let the JFrame completely exposed,but there are still some shadow (the originally overlaped region) on the first JFrame.The shadow does NOT disappear until the taskProgram finished.

Why is the shadow caused?The sychonized function blocks the Java main thread?

How to avoid this problem? Thanks.

[648 byte] By [princesuna] at [2007-10-3 2:56:02]
# 1
> The taskProgram is a> little time-consuming and it will show another> taskMonitor window.That task is hogging up the Event Dispatch Thread which prevents your frame from repainting. If you put it in a separate thread the problem should go away.
BinaryDigita at 2007-7-14 20:45:10 > top of Java-index,Desktop,Core GUI APIs...
# 2
[url http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html]How to Use Threads[/url]
camickra at 2007-7-14 20:45:10 > top of Java-index,Desktop,Core GUI APIs...
# 3
I am just puzzled that:In a JFrame, open a Modal dialog,the modal dialog is also hogging up the Event Dispatch Thread, right?But in this case, the JFrame still get chance to be repained although no action can be done on that JFrame.Why?
princesuna at 2007-7-14 20:45:10 > top of Java-index,Desktop,Core GUI APIs...
# 4

Code executes sequentially. So if you have a long running task executing in the EDT, then the EDT can't respond to events until the long running task is finished.

> the modal dialog is also hogging up the Event Dispatch Thread, right?

No. No CPU cycles are used while the dialog is open. It just sits there waiting for you to generate events. All the event code is then executed in the EDT. But unless this code is a long running task it will execute quickly and free up the EDT.

The difference is that when you attempt to click outside of the dialog, the mouse click event is intercepted and focus is placed back on the modal dialog. Don't confuse this "intercepting" of events with "hogging" the CPU.

camickra at 2007-7-14 20:45:10 > top of Java-index,Desktop,Core GUI APIs...
# 5
camickr , thanks. I understand now.
princesuna at 2007-7-14 20:45:10 > top of Java-index,Desktop,Core GUI APIs...