I'm trying to use getImage()
do display an image on a JPanel
in an application I'm writing. I've tried and tried to get this to work for me, and eventually discovered that even when the path is totally incorrect, it still does not work, nor does it return NullPointerException
as would be expected.
Image i;
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.drawImage(i, 0, 0, 200, 200, this);
} // end paintComponent();
public Pnl() {
super();
setBackground(Color.GREEN);
setBorder(BorderFactory.createLineBorder(Color.GRAY, 10));
i = Toolkit.getDefaultToolkit().getImage("shrek.jpg");
} // end constructor
When I run the code with a parameter such as "shrek...jdhhd" in getImage()
or something of that sort, it does exactly the same thing.