I am working on a program that should auto adjust a bar depending on the value I read from a file or array. I have placed two JPanel inside one another one is static and the other should get its values from the array/file. My problem is as you read the array or file I want to update the parameters of the JPanel. below is my example code.
int myvalues[] = {120,130,140,150,160,170,180};
for(int i = 0; i <= myvalues.length-1; i++){
guagePanel.setSize(10,myvalues[i]);
Thread.sleep(1000);
}
But the above is not getting the page refreshed.
Don’t sleep on the event dispatch thread. Instead, use a
SwingWorkerin combination with aJProgressBar, as shown in How to Use Progress Bars. If you’re reading from a file,ProgressMonitorInputStreammay be convenient.