I am creating a game in java swing, i have a loading gif i want to play while loading. This is the code i have:
URL path = ClassLoader.getSystemResource("loading.gif");
Image gif = new ImageIcon(path).getImage();
JLabel loadingGif = new JLabel(new ImageIcon(gif.getScaledInstance(200, 200, Image.SCALE_DEFAULT)));
loadingGif.setLocation(something, something);
window.getContentPane().add(loadingGif);
window.setComponentZOrder(loadingGif, 0);
window.repaint();
The issue is that if insted of loading.gif in the url i have a something_else.png it all works fine, if instead i have a gif, it flickers.
Any ideas on how to fix that?