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.
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
SwingWorkerclass.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
JFrameand it becomes unresponsive.