Answer the question
In order to leave comments, you need to log in
How to insert GIF into JLable (what animation was visible) JAVA SWING?
In general, the question is very stupid, but for a very long time I can not solve this problem.
How to insert a GIF into a JLable (so that the animation can be seen)?
I paste the png like this:
URL url_img = getClass().getResource("image/image.png");
Image img = ImageIO.read(url_img);
Image image = img.getScaledInstance(my_lable .getWidth() - 50, my_lable .getHeight(), Image.SCALE_AREA_AVERAGING);
my_lable .setIcon(new ImageIcon(image));
Answer the question
In order to leave comments, you need to log in
package ru.test;
import javax.swing.*;
import java.awt.*;
public class Main
{
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
JFrame frame = new JFrame("test");
frame.setSize(800, 400);
JLabel jLabel = new JLabel("test");
Image image = Toolkit.getDefaultToolkit().createImage("/home/valor/images/gifs/ajax-loader-round.gif");
ImageIcon imageIcon = new ImageIcon(image);
imageIcon.setImageObserver(jLabel);
jLabel.setIcon(imageIcon);
frame.add(jLabel);
frame.setVisible(true);
}
});
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question