Some images are not appeared  on the JButton

10-11  Source: Network gathering  Views:0 

Advertisement
Hi all
I want to appear an ImageIcon on my JButton
Some images are appeared on the button when run the code,
but some images are not and the button appeared as a default
button why ?
the problem in my code in this statement
JButton   merc = new JButton (new ImageIcon(" door.jpg " ));Thanks in advance.
I suggest that you break down your statements even further to see where the problem is.
So if this the problem is on this line:
JButton   merc = new JButton (new ImageIcon("door.jpg" )); //string corrected?try to break it up a bit like so:
JButton merc = new JButton();
File imageFile = new File("door.jpg");
if (imageFile.exists())
   ImageIcon icon = new ImageIcon(imageFile);
   if (icon != null)
      merc.setIcon(icon);
   else
      System.out.println("icon == null");
else
   System.out.println("image file doesn't exist");
}
Related articles