Skip to content
Sign upLog in
← Back to Community
Can someone tell me what is wrong with my code?
Profile icon
MINHTO

I try to set an ImageIcon to my JButton, but it seems to not work. The code where I give the button the icon is in the Display class. The code where I load in the BufferedImage and then convert it into an ImageIcon is in the Asset class.

Voters
Profile icon
MINHTO
Comments
hotnewtop
Profile icon
MINHTO

No, it doesn’t work. Thx though.

Profile icon
Nemoiscool

I found it. The reason your image is not showing up is because the file you reference in the code does not exist. you have two images in the 'res' folder:

'red_square.jpg' and
'red_square_2_.jpeg'

The file you reference in the code is 'red_square.jpeg.' All you need to do is remove the 'e' in 'jpeg.' Then it should work.