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));
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);
}
});
}
}