import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author LordLuzifer
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setLayout(null);
frame.setSize(300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
JPanel panel = new MyPanel();
panel.setBounds(0,0,200,200);
frame.add(panel);
frame.validate();
frame.repaint();
}
}
class MyPanel extends JPanel {
BufferedImage img;
@Override
public void paintComponent(Graphics gra) {
Graphics2D g = (Graphics2D) gra.create();
try {
img = ImageIO.read(new File("test.bmp"));
} catch (IOException ex) {
}
if (img != null) {
g.drawImage(img, 0, 0, null);
}
}
}
JLabel label = new JLabel();
ImageIcon icon = new ImageIcon("resources/images/myImage.jpg");
label.setIcon(icon);
JLabel label = new JLabel();
ImageIcon icon = new ImageIcon("resources/images/myImage.jpg");
Image img = icon.getImage().getScaledInstance(150 , 250, Image.SCALE_DEFAULT);
label.setIcon(new ImageIcon(img));