IJ.showProgress in java



I’ve got a question relation to the IJ.showProgress() function.
I am using it a computationally expensive for-loop in a java plugin and it does not show the progress.

I found this:

There it is mentioned that one needs to create different threads…?
Is that really necessary? And if so, could someone maybe show me an example of how to do this?


Found out myself:

Thread t1 = new Thread(new Runnable() {
                        public void run() {

Where myFunction contains above mentioned for-loop


And that solves your issue, i.e. shows the progress bar as expected?

I wonder if the IJ2 way of doing it (using StatusService) would work better for you:

import org.scijava.app.StatusService;

// ...

final StatusService sts;

// ...

sts.showProgress(current, total)


Hi Jan,

My way works for me…however, depends a bit on the OS. Works even more reliably if the status update and the computation run in different threads. I did not try your suggestion yet, but thanks for the suggestion!


you can use the following

final AtomicInteger progress = new AtomicInteger(0); // the progress to show


Thread t1 = new Thread(new Runnable() {
                        public void run() {
                           myFunction(..., progress);

and in MyFunction

  private void myFunction(..., AtomicInteger progress) {
    IJ.showProgress(progress.getAndIncrement(), total);


FWIW, the SciJava status service currently does not do any magic threading or batching of status events. However, SciJava commands already run on their own thread. On my system, the following script works as expected:

// @StatusService ss
max = 1000
for (i=0; i<max; i++) {
	ss.showStatus(i, max, "Processing " + i + "/" + max)

@Christian_Tischer What kind of plugin are you using? A SciJava Command? Or a legacy ImageJ 1.x PlugIn? If the latter, try the former instead.



Thanks for the code!

As I am using the Swing GUI anyway I am doing now all my progress logging via the invokeLater function, e.g. like this:

public static void threadLog(final String log) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

That works OK for me.


That is fine—it just ties you to the legacy ImageJ 1.x codebase, as well as Swing UIs in particular. In other words, it is not flexible, and not future-proof. But it gets the job done for your narrower scope.