The question is published on by Tutorial Guruji team.
I’m trying to make a chessboard (8×8 grid) and fill it with background squares, but it always appears as a grid of empty squares. The image is called
emptysquare.jpg but it does have a background color.
How to I correctly add an image to a
JButton on the grid I have?
The reason that your chessboard is empty is due to the fact that you call
JFrame#setVisible before adding your
ChessSquare buttons to your panel. Ensure all component have been added before making this call.
Also set the
Icon like this in
ImageIcon empty = ... setIcon(empty);