I want to show a gif in java swing.
For show gif I use from these code but in both of them the gif is not moving and it like as an image is static.
first code:
void showGif() {
try {
JPanel panel = new JPanel();
BufferedImage bufferedImage = ImageIO.read(new File("address of gif");
Icon icon = new ImageIcon(bufferedImage);
JLabel label = new JLabel(icon);
label.setVisible(true);
panel.add(label);
} catch (IOException e) {
e.printStackTrace();
}
}
second code:
void showGif() {
try {
ImageIcon imageIcon;
BufferedImage bufferedImage = ImageIO.read(new File("address of gif"));
imageIcon = new ImageIcon(bufferedImage);
JLabel label = new JLabel(imageIcon);
JPanel panel = new JPanel();
label.setVisible(true);
panel.add(label, TOP_ALIGNMENT);
} catch (IOException e) {
e.printStackTrace();
}
}
please help me to show gif correctly.