I am trying to implement a progress JDialog in Java. I am parsing files, and I want the JDialog to refresh after I started to parse a new File. My problem is that the JDialog is not refreshing. I have tried to repaint it, or resize it, so it would repaint. I have also tried to remove the label, and add a new one.
The ProgressDialog class:
public class ProgressDialog extends javax.swing.JDialog {
private JLabel jLabel1;
public ProgressDialog(Window frame) {
super(frame);
this.setResizable(false);
this.setLocationRelativeTo(frame);
initGUI();
//this.setVisible(true);
}
private void initGUI() {
try {
{
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
getContentPane().setLayout(null);
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("In Progress..");
jLabel1.setBounds(12, 12, 215, 52);
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
}
}
this.setSize(255, 114);
} catch (Exception e) {
e.printStackTrace();
}
}
public void setText(String s){
this.setVisible(true);
jLabel1.setText(s);
this.resize(this.getSize());
this.repaint();
}
}
How I use it:
ProgressDialog pd = new ProgressDialog(frame);
for(File file:files){
pd.setText("Parsing " + file + ".");
...
}