1

I want to change the value of a JSlider in a panel, while I'm running a Thread which give's me this value (because of some progress)

So i calculate the progress-value in the Thread, and with a GET-method I fetch the value in the panel and want to set it to the progressbar.

After debugging it, a value is there but the EDIT:[ JProgressBar ] don't change his UI.

Some code:

while(_thread.isAlive()) {
 pb_calc.setValue(_thread.getVal());
 pb_calc.updateUI();
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Christian 'fuzi' Orgler
  • 1,682
  • 8
  • 27
  • 51

1 Answers1

4
  • dont use updateUI, this method is reserved for Look and Feel and UIManager

  • output from Background Tasks should be wrapped into invokeLater, more in the tutorial Concurency in Swing

  • better would be invoke Background taks from SwingWorker or inside Runnable#Thread

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • can you give me an example what y mean? – Christian 'fuzi' Orgler Apr 19 '12 at 15:28
  • 1
    @Christian 'fuzi' Orgler check my profile here, there are examples to my last point – mKorbel Apr 19 '12 at 16:27
  • 2
    @Christian'fuzi'Orgler http://stackoverflow.com/questions/8916721/java-swing-update-label/8917565#8917565 is an example. The Swing tutorials also contain one (follow the link in the JProgressBar class javadoc ... how convenient is that) – Robin Apr 19 '12 at 17:21