我正在尝试使用以下代码在 JLabel 内显示 GIF 图像
Image waitImage = null;
JLabel l1;
try {
waitImage = ImageIO.read(IndexesPanel.class.getResource("/images/error.gif"));
l1 = new JLabel(new ImageIcon(waitImage));
l1.setBounds(20, 20, 100, 100);
waitPanel.add(l1);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
图像已显示,但不是动画。我正在使用以下 Gif:
有什么想法吗?
最佳答案
ImageIO
返回BufferedImage
使用new ImageIcon(new URL("资源路径"));
我猜你可以使用new ImageIcon(IndexesPanel.class.getResource("/images/error.gif"))
;
关于Java:显示 GIF 图像不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22353639/