#Java swing - Gif flickering

4 messages · Page 1 of 1 (latest)

feral pilot
#

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?

mighty phoenixBOT
#

This post has been reserved for your question.

Hey @feral pilot! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

spiral yew
#

I'm sure weirded out that the effect exists with some image format and not with another.
Would your gif happen to have some transparent background and your png not?