简体   繁体   中英

Swing application problem

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 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.

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM