Java Swing Animation Loading

I would like to implement the following boot animation with java swing:

enter image description here

The circle should rotate clockwise.

What would be the best way to do this?

Many thanks.

+6
source share
4 answers

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

+4
source

Just use ImageIcon and an animated gif. see setImageObserver in ImageIcon.

Icon loading can be done using various online generators such as AjaxLoad .

+9
source

Hope it's not too late for this.

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

private JPanel loadingPanel() { JPanel panel = new JPanel(); BoxLayout layoutMgr = new BoxLayout(panel, BoxLayout.PAGE_AXIS); panel.setLayout(layoutMgr); ClassLoader cldr = this.getClass().getClassLoader(); java.net.URL imageURL = cldr.getResource("img/spinner.gif"); ImageIcon imageIcon = new ImageIcon(imageURL); JLabel iconLabel = new JLabel(); iconLabel.setIcon(imageIcon); imageIcon.setImageObserver(iconLabel); JLabel label = new JLabel("Loading..."); panel.add(iconLabel); panel.add(label); return panel; } 

Some points of this approach:
1. The image file is in the bank.
2. ImageIO.read () returns a BufferedImage that does not update ImageObserver.
3. Another alternative for finding images included in the jar file is to ask the Java class loader, the code that loads your program, to get the files. He 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.

+6
source

This can be done using a custom component or a custom icon using regular Java2D calls. For me, it looks like Arc2D with a rather thick BasicStroke drawn using GradientPaint .

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

+3
source

Source: https://habr.com/ru/post/905486/


All Articles