I don't understand why the progress bar does not move in the following code:
JDialog dlgProgress = new JDialog(InterfaceYadis.frameInterface, "Veuillez patienter...", true);
JLabel lblStatus = new JLabel("Test");
JProgressBar pbProgress = new JProgressBar(0, 100);
pbProgress.setIndeterminate(true);
dlgProgress.add(BorderLayout.NORTH, lblStatus);
dlgProgress.add(BorderLayout.CENTER, pbProgress);
dlgProgress.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
//dlgProgress.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dlgProgress.setSize(300, 90);
dlgProgress.setLocationRelativeTo(null);
SwingWorker<Void, Void> sw = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
Thread.sleep(2500);
return null;
}
@Override
protected void done() {
dlgProgress.dispose();
}
};
sw.execute();
dlgProgress.setVisible(true);
The JDialog should be executed on UI thread and the progress bar should move from left to right ? Thanks.
EDIT:
The problem is not on the code, before, i have created a custom JProgressBar and i have modified the repaint interval and cycle time defaults... Custom Jprogress was setting :
UIManager.put("ProgressBar.repaintInterval", new Integer(50));
UIManager.put("ProgressBar.cycleTime", new Integer(100));
The default setting is :
INTERVAL = UIManager.getInt("ProgressBar.repaintInterval"); // = 50
CYCLETIME = UIManager.getInt("ProgressBar.cycleTime"); // = 3000
For me, I have two solutions:
1 / I defined the cycle and the interval each time to be sure to have the right values
2 / I use the same everywhere progressbar
I think the solution 2 is the best, but I like to know if the solution one can be a good solution too.