How to update jprogress panel

There is a simple JForm and JDialog in my application. The JDialog box contains the JProgressBar tab, and I use the method in JDialog as

public void updateProgress(int val){ prgProgress.setValue(val); //prgProgress-> name of the JProgressBar } 

to update the progress bar.

When I try to update the progress bar in JDialog from JForm, the JProgressBar is not updating, as expected, tell me what might be the error.

Ref.

 public class Status extends javax.swing.JDialog{ private javax.swing.JProgressBar prgProgress = new javax.swing.JProgressBar; ..... public void updateProgress(int val){ prgProgress.setValue(val); //prgProgress-> name of the JProgressBar } ..... } public class MyForm extends javax.swing.JInternalFrame { Status s = new Status(); s.setVisible(true); for(int i=0; i<100; i++){ s.updateProgress(i); } } 
+2
source share
2 answers

You have a problem with Concurency in Swing , Swing is single-threaded and nothing happens if you update the GUI from EDT, you have to Add SwingWorker to update JProgressBar , example with descriptions here

+1
source

Firstly, I do not see from your code above showing that you added JProgressBar to JDialog , but I assume that you did. Secondly, you did not set the maximum value of JProgressBar , both from the constructor and from the setMaximum() member setMaximum() . This may be the reason for the lack of progress.

See also:

http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html

+1
source

All Articles