在jPanel上显示动画gif [英] Display animated gif on jPanel
本文介绍了在jPanel上显示动画gif的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 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);
}
如何更改此项以便显示gif上的动画(不使用线程)。我花了很多时间试图让它工作但无济于事。
How can I change this so the animation on the gif is shown (without using threading). I have spent many hours trying to get this to work but to no avail.
推荐答案
你可以使用 ImageIcon
就此而言。看看这里和这里。如果您需要 JPanel
上的动画,只需添加 JLabel
(使用 ImageIcon
)到面板。
You could use an ImageIcon
for this purpose. Have a look here and here. If you need the animation on a JPanel
, simply add a JLabel
(with the ImageIcon
) to the panel.
这篇关于在jPanel上显示动画gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文