JProgressBar doesn't, well, progress...
I am trying to make a progress bar. RIght now, all it does is say 0% complete for the length of the task, and then jumps to 100%. Can anyone tell me what is wrong with this?
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.beans.*;
import javax.swing.SwingWorker.*;
publicclass RunMethodextends SwingWorker<Void, Void>implements PropertyChangeListener{
public JProgressBar progressBar;
public Void doInBackground(){
setProgress(0);
returnnull;
}
publicvoid ProgressBar(String filenamed, String file2named)throws IOException{
JFrame pFrame =new JFrame();
pFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pFrame.setLayout(new BorderLayout());
progressBar =new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
JPanel panel =new JPanel();
panel.add(progressBar);
pFrame.add(panel, BorderLayout.CENTER);
pFrame.setLocationRelativeTo(null);
pFrame.setSize(200,100);
pFrame.setVisible(true);
//setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
RunMethod runMethod =new RunMethod();
runMethod.addPropertyChangeListener(this);
runMethod.runMethod(filenamed, file2named);
}
publicvoid runMethod(String filename, String file2name)throws IOException{
int progress = 0;
setProgress(progress);
//There's a bunch of code here, don't need to include it
int progress = 5;
setProgress(progress);
//And I have a bunch of setProgress's throughout, all the way to 100
}
publicvoid propertyChange(PropertyChangeEvent evt){
if ("progress" == evt.getPropertyName()){
System.out.println("here");
int progress = (Integer) evt.getNewValue();
progressBar.setValue(progress);
}
}
I have determined that the propertyChange method doesn't get called until after the task is complete.
don't rule out me doing something really obvious wrong, I'm new...
Thanks for the help

