I want to resize my picture, but there is always an error with displaying it.
How can I do it?
public class Panel extends JPanel {
private ImageIcon imgIcon;
public Panel(){
super();
File imageFile=new File("mar.jpg");
try {
BufferedImage bi = ImageIO.read(imageFile);
ImageIcon imgIcon = new ImageIcon(bi);
imgIcon = new ImageIcon(bi.getScaledInstance(400,400, Image.SCALE_DEFAULT));
} catch (IOException e) {
System.err.println("error");
e.printStackTrace();
}
Dimension dimension=new Dimension(1400,1000);
setPreferredSize(dimension);
}
@Override
public void paintComponent(Graphics g){
Graphics2D g2d=(Graphics2D)g;
g2d.drawImage(imgIcon.getImage(),0,0,this);
}
}