Swing Progress Dialog

How can I make a modal JDialog without buttons appear for the time it takes to complete the Runnable instance and so that the instance updates the progress bar / message in this dialog box?

Obviously spaghetti code may work, but I'm looking for a clean design if one exists.

+4
source share
3 answers

You might want to explore ProgressMonitor . It automatically displays a dialog with a progress bar if the operation takes a lot of time; see How to use progress monitors .

+8
source

Have a look at the project described at the following URL: http://digilander.libero.it/carlmila/compmon/main.html

This is a free Java library, an alternative to Swing ProgressMonitor.

+2
source

Use a monitor class with a global instance and which your code is updated (I am starting, I am working, I am at xxx%, I am finished).

Then the monitor can decide to show the dialog and keep it up to date. Later, you can simply replace the dialog with a progress bar in the status bar, for example. Use the monitor interface (methods: start (), update (), end (), error (), isAborted ()) so that you can replace it with something else.

You can expand the monitor to 500 ms after starting (), if there is an end (), and not show a dialog in this case, etc.

This is how Eclipse does this and it works well.

+1
source

All Articles