Reputation: 13
I'm using Jframe
form for this program and here's the button code I've tried. When I ran the program and clicked the button nothing happens. Pls help.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
ImageIcon icondir = new ImageIcon("C:\\Users\\Awesome\\Desktop\\myaJbQq.jpg");
ID_Background.setIcon(icondir);
}
Upvotes: 0
Views: 58
Reputation: 1168
ID_Background.repaint();
Should fix your issue. If not, I'm going to need more code than what you've provided (what the ID_Background is, how your GUI is setup, etc).
Upvotes: 0
Reputation: 264
This file (image) C:\\Users\\Awesome\\Desktop\\myaJbQq.jpg
does not exists.
The problem with ImageIcon
is that is not throwing any exception if the file/resource is missing.
Try to load the icon this way:
ImageIcon icondir = new ImageIcon(
ImageIO.read(
new File("C:\\Users\\Awesome\\Desktop\\myaJbQq.jpg")));
You will have for sure an exception:
Exception in thread "main" javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
...
Upvotes: 1