I Would like to realize the following loading animation with java swing :
The circle has to spin clockwise.
What would be the best way to make it ?
Thank you very much.
I Would like to realize the following loading animation with java swing :
The circle has to spin clockwise.
What would be the best way to make it ?
Thank you very much.
You can use the Animated Icon class to create your own animation using your existing icon.
This could be drawn with a custom component or a custom icon, using regular
Java2D
calls. To me it looks like anArc2D
with a fairly thickBasicStroke
drawn with aGradientPaint
.Alternately, export frames from Inkscape (or other graphics program) and load them as images.
Hopefully it's not too late for this.
I managed to get the animated gif inside my JPanel this way:
Some points of this approach:
1. The image file is within the jar;
2. ImageIO.read() returns a BufferedImage, which doesn't update the ImageObserver;
3. Another alternative to find images that are bundled in the jar file is to ask the Java class loader, the code that loaded your program, to get the files. It knows where things are.
So by doing this I was able to get my animated gif inside my JPanel and it worked like a charm.
Just use an ImageIcon and an animated gif. see setImageObserver in ImageIcon.
Loading icons can be made using a variety of online generators such as AjaxLoad.