2

I have created a Swing JProgresBar and set indeterminate to "true". The progress bar works correctly but it cycles extremely fast and the it's annoying to look at for longer than 3 seconds. I want to slow it down and I thought there would be a method for this. If there is a method I haven't found it yet. Any help would be greatly appreciated.

sftpProgressBar.setIndeterminate(true);
sftpDialog.setVisible(true);
Conner
  • 413
  • 2
  • 8
  • 20
  • 1
    Can you show us some code about how you are doing that? – evanwong May 14 '12 at 17:35
  • 1
    This is pretty much it. I used the Swing Design Window to construct the UI. Here is what I do to display and set it to indeterminate. sftpProgressBar.setIndeterminate(true); sftpDialog.setVisible(true); I apologize in advance for the code formatting. Not sure how to do that in the comments on here. – Conner May 14 '12 at 17:46
  • 1
    *"code formatting. Not sure how to do that in the comments on here."* **Don't** put code in comments. Edit it back into the question. – Andrew Thompson May 14 '12 at 17:52
  • Thanks Andrew. I've edited the question and added the sample code. – Conner May 14 '12 at 18:16

3 Answers3

2

You can control the animation speed of a JProgressBar. See the documentation:

The "ProgressBar.cycleTime" UI default lets look and feel implementers (as well as other developers)specify how many milliseconds each animation cycle takes. For example, a cycle time of 500 means that the indeterminate-mode progress bar animation repeats twice per second.

Jasper Siepkes
  • 1,412
  • 16
  • 25
  • I tried using cycleTime but it did not come up as a method I could use. Maybe it's a different type of progress bar? – Conner May 15 '12 at 18:04
  • @Conner As far as I know there is only one progressbar in Swing and thats the JProgressBar. Maybe the values are being overridden by the selected Look and Feel (Nimbus, Metal, etc). – Jasper Siepkes May 17 '12 at 16:10
1

Well, this is how I fixed the problem. In "main" there was some generated code that I commented out. The only thing that changed was the progress bar. It slowed down to a much slower and more visibly pleasing speed. This is the code I commented out.

try {
  for (javax.swing.UIManager.LookAndFeelInfo info :  javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
        javax.swing.UIManager.setLookAndFeel(info.getClassName());
        break;
  }
}
Conner
  • 413
  • 2
  • 8
  • 20
1
 UIManager.put("ProgressBar.repaintInterval", new Integer(250));
 UIManager.put("ProgressBar.cycleTime", new Integer(6000));

ProgressBar.cycleTime: is the parameter using you can specify how many milliseconds each animation cycle takes . You can refer details in link

Mahantesh M Ambi
  • 786
  • 1
  • 13
  • 25