0

This is the function I am implementing in the frame that opens up after clicking the button on a previous frame... The frame for the progress bar opens up easily, but the progress is not shown... please, help me solve this.

public void iterate() {
    while (num < 2000) {
        current.setValue(num);
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) { }
        num += 95;
    }
}
Sonny
  • 8,204
  • 7
  • 63
  • 134
  • You can take a look at this [example](http://stackoverflow.com/questions/16288303/best-example-for-creating-programmatically-splashscreen-with-text/16289376#16289376) – Guillaume Polet Mar 05 '14 at 20:48

1 Answers1

4

Your problem is that you're doing a long-running bit of code on the Swing event thread, and this will put the Swing event thread, and your entire GUI with it, to sleep.

The solution, do the long running bit of code in a background thread such as is available through a SwingWorker, either that or use a Swing Timer to advance your number and forgo the while (true) and the Thread.sleep(...).

Also note that your second dependent window should be a dialog such as a JDialog or a JOptionPane, not another JFrame.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373