-1

I really need help with probably so simple bug. I'm trying to load icon on my button but with some reason it keeps showing me just regular button. Here is how i tried so can anybody say me where i'm making it wrong.

buttonList[i]= new JButton();
        buttonList[i].setIcon(new ImageIcon("C:\\img\\icon.bmp"));

2 Answers2

0

I could be wrong here, and someone correct me if I am, but I believe that the supported file types for ImageIcon are JPEG, GIF, and PNG. So the error would be that your icon is a .bmp file.

The easiest way to change that would be to load it into MSPaint, and just click Save As and change the file type to either JPEG or PNG.

Nicholas Eason
  • 290
  • 4
  • 13
0

From ImageIcon()

"When specifying a path, use the Internet-standard forward-slash ("/") as a separator. (The string is converted to an URL, so the forward-slash works on all systems.) For example, specify:"

new ImageIcon("images/myImage.gif")

This may not be the problem, but it would be preferable. Perhaps you need to repaint().

Community
  • 1
  • 1
Jool
  • 1,706
  • 16
  • 14