Take the 2-minute tour ×

I Would like to realize the following loading animation with java swing :

enter image description here

The circle has to spin clockwise.

What would be the best way to make it ?

Thank you very much.

share|improve this question
Swapping a bunch of sprites could work for this. Of course the loading would have to be done in a background thread, such as that provided by a SwingWorker. –  Hovercraft Full Of Eels Jan 9 '12 at 3:17
See also this Q&A. –  trashgod Jan 9 '12 at 3:38

4 Answers 4

up vote 3 down vote accepted

You can use the Animated Icon class to create your own animation using your existing icon.

share|improve this answer

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.

share|improve this answer
VERY NICE! useful! –  martini Sep 12 '12 at 16:50

This could be drawn with a custom component or a custom icon, using regular Java2D calls. To me it looks like an Arc2D with a fairly thick BasicStroke drawn with a GradientPaint.

Alternately, export frames from Inkscape (or other graphics program) and load them as images.

share|improve this answer

Hopefully it's not too late for this.

I managed to get the animated gif inside my JPanel this way:

private JPanel loadingPanel() {
    JPanel panel = new JPanel();
    BoxLayout layoutMgr = new BoxLayout(panel, BoxLayout.PAGE_AXIS);

    ClassLoader cldr = this.getClass().getClassLoader();
    java.net.URL imageURL   = cldr.getResource("img/spinner.gif");
    ImageIcon imageIcon = new ImageIcon(imageURL);
    JLabel iconLabel = new JLabel();

    JLabel label = new JLabel("Loading...");
    return panel;

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;

So by doing this I was able to get my animated gif inside my JPanel and it worked like a charm.

share|improve this answer

Your Answer


