-1

I am trying to simulate a progressbar process using a for loop. The whole loop represent 100% so as the loop increases, the progressbar should also increase until the loop is done it will be 100% However in netbean UI the progress bar doesnt show as expected.

    int i;
    progressBar.setStringPainted(true);
    for (i = 0; i < 99999; i++) {
        i = i;
        progressBar.setValue(i);
        System.out.println(i);
    }
    progressBar.updateUI();
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
BeyondProgrammer
  • 893
  • 2
  • 15
  • 32

2 Answers2

0

you can't do that unless the progress bar is in it's own thread. Then you access the progress bar from a different thread, This is because the progress bar will not update until the for loop is entirely done in a single thread.

So, create a new thread with the gui in it.

snocavotia
  • 435
  • 1
  • 3
  • 13
0

Try updating the progressBar UI just after setting value.

    int i;
    progressBar.setStringPainted(true);
    for (i = 0; i < 99999; i++) {
        i = i;
        progressBar.setValue(i);
        progressBar.updateUI();
        System.out.println(i);
    }
Thudani Hettimulla
  • 754
  • 1
  • 12
  • 32