-4

I have a program where when the user clicks a certain button I want a small new frame to appear with a progress bar. I do not want the user to be able to do any other thing until the process is finished. I am having troubles updating the progress bar when I place it in a separate frame that pops up when the button is pressed. If I place the progress bar in the same panel as the button then it updates correctly, but this is not what I want. I need it to be in a new frame and I need the user to have to wait for it to finish. How can I do that? Thanks.

I create the frame with the following code:

void designProgressFrame() {
    progressFrame = new JFrame("Progress");
    progressFrame.getContentPane().setLayout(new BoxLayout(progressFrame.getContentPane(), BoxLayout.PAGE_AXIS));
    progressFrame.setSize(200, 100);
    JPanel panel1 = new JPanel();
    JPanel panel2 = new JPanel();
    panel1.setBackground(new Color(248, 248, 244));
    panel2.setBackground(new Color(248, 248, 244));
    progressFrame.getContentPane().setBackground(new Color(248, 248, 244));
    progressBar = new JProgressBar();
    progressBar.setStringPainted(true);
    progresslbl = new JLabel();
    panel1.add(progressBar);
    panel2.add(progresslbl);
    progressFrame.getContentPane().add(panel1);
    progressFrame.getContentPane().add(panel2);
    progressFrame.setLocationRelativeTo(null);
} 

and once a certain button is pressed in my main program I make this frame visible and start updating the progress bar using the setValue() method, but for some reason the bar is not updated.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user3245747
  • 805
  • 2
  • 17
  • 30
  • 3
    (a) Show code. (b) If you can't be bothered to accept answers to your questions, I can't be bothered to help you. You have 27 questions and 0 of them are marked answered. – Eric Stein May 13 '14 at 17:43
  • The questions marked unanswered are either unanswered or I found the solution myself. – user3245747 May 13 '14 at 18:02
  • 1
    @user3245747 If you found the solution yourself, go back to those questions, add your own answer and mark it as the accepted answer so others can benefit. – Sven Grosen May 13 '14 at 18:26

1 Answers1

0

The problem turned out to be a concurrency problem. The answer provided by mKorbel on this link solved the problem. All I had to do was to use SwingWorker:

JProgressBar in new thread JDialog

Community
  • 1
  • 1
user3245747
  • 805
  • 2
  • 17
  • 30