4

I want to add a simple Circle progress bar in my Java GUI application, to let the user understand, that there some network/download application. So what I want is something like this:

enter image description here

And in the code:

waitingBar.start(); 
myLongOperation();
waitingBar.stop();

I found this solution, which should be good as the layout, but it doesn't work, because I got this problem:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: alpha value out of range at java.awt.AlphaComposite.(AlphaComposite.java:618) at java.awt.AlphaComposite.getInstance(AlphaComposite.java:683) at gui.WaitLayerUI.paint(WaitLayerUI.java:41)

I have the external class, which calls the method start(); before the longOperation(); and then execute stop();. The JFrame is initialized directly in the Main.

So my question is:

  1. Is there something very simple to obtain the circle bar appear and dissapear ?
  2. How Can I fix the problem I'm facing with that solution ?
Community
  • 1
  • 1
I love coding
  • 1,183
  • 3
  • 18
  • 47
  • 1
    It seems like you are setting a colour to any component which throws this error, since it is out of the normal colour range – SomeJavaGuy Apr 08 '15 at 13:20
  • `alpha value out of range` - so fix the problem. Don't let the alpha value go out of range. Here is the Swing tutorial link on [Decorating Components With JLayer](http://docs.oracle.com/javase/tutorial/uiswing/misc/jlayer.html) – camickr Apr 08 '15 at 14:38
  • They forgot to set `mIsRunning` to `false` in `stop()` method. just add it and `IllegalArgumentException: alpha value out of range` will disappear. – andronix Apr 07 '16 at 22:37

1 Answers1

3

Have you considered using animated GIF or animated PNG? With these types images you can display the image and hide the image without any fancy stuff and it'll give you the animation that you need.

cher
  • 51
  • 3