views:

241

answers:

4

I'm developing Swing application, and everything works fine usually. But I have an GUI issue.

When I run the application, and for example minimize some other window, my application is still working, but the central part of JFrame is invisible or hidden. After finishing some part of program logic the GUI repaints and is visible again. This will continue until the program finishes running.

Is there any API for preventing this behavior, or some class for forcing the GUI visible, or maybe to add some progress bar?

If someone need this information I'm testing this on Windows Vista, with java 1.6.

+9  A: 

It sounds to me like you are doing some sort of slow IO or calculations that are causing your GUI to become unresponsive.

What you need to do is do the long running processes in another thread.

The standard way of doing that is with a SwingWorker class.

The Java tutorials have some great resources and tutorials on how to properly use the SwingWorker.

Here and here is a link to another question that I believe may be similar.

This behavior you are seeing is a result of your long running process blocking the thread that the GUI uses to repaint itself. Thus, while your task is performing, the GUI is unable to repaint your JFrame and it becomes unresponsive.

jjnguy
There are some cases where Swing forgets to repaint itself when the window area becomes dirty under Windows. Have a Swing Timer run in every couple of seconds and issue a repaint() to the window.
kd304
When a window becomes reactivated (regains focus), it will repaint itself by default.
jjnguy
Adding a timer may help, but the GUI can't repaint itself if the thread is blocked.
jjnguy
Yes I make some slow IO calculations, thanks for respond.
vaske
My case did not involve any EDT blocking operation. I guess it was related to some 'properties' of the underlying d3d pipeline.
kd304
A: 

Try this question.

Jeremy Smyth
+2  A: 

Just like jinguy says you are most likely doing a task that takes a long time to complete and needs to be put in a background thread. Have a look at the Java Sun Concurrency in Swing Tutorial for more information on how to do this correctly.

willcodejavaforfood
+2  A: 

It seems you need to perform your long running business operations in a separate thread. I suggest you use a SwingWorker.

Check this simple example.

bruno conde