[英]Display animated gif on jPanel
In the overridden function for my JFrame
: 在我的
JFrame
的重写函数中:
@Override
protected void paintComponent(Graphics g) {
BufferedImage imagePerson;
try {
imagePerson = ImageIO.read(new File("errol.gif"));
} catch (IOException e) {
imagePerson = null;
}
g.drawImage(imagePerson, i * increment, j * increment - 1, null);
}
How can I change this so the animation on the gif is shown (without using threading). 如何更改此设置以显示gif上的动画(不使用线程)。 I have spent many hours trying to get this to work but to no avail.
我花了很多时间试图让它工作,但无济于事。
Check this example for displaying an animated gif in Swing. 检查此示例以在Swing中显示动画gif。 you dont have to use any threads:
你不必使用任何线程:
Icon imgIcon = new ImageIcon(this.getClass().getResource("ajax-loader.gif"));
JLabel label = new JLabel(imgIcon);
label.setBounds(668, 43, 46, 14); // for example, you can use your own values
frame.getContentPane().add(label);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.