There are, at least, two things that stand out...
Firstly:
private static final String imageFolderPath = "src/resources/images/";
It's unlikely that the directory src
will exist once the application is built.
Second:
ImageIcon icon = new ImageIcon(imageFolderPath+"/pieces/blank.png");
ImageIcon(String)
denotes that the reference resource is a file on the file system. Based on the value of imageFolderPath
this doesn't seem your likely intention. Instead, it seems you are trying to use these images as embedded resources, in which case you should be using something more like...
ImageIcon icon = new ImageIcon(getClass().getResource("/resources/images/pieces/blank.png"));
Personally, I would use ImageIO
instead, at least this will throw an IOException
if the image can't be loaded...
try {
BufferedImage img = ImageIO.read(getClass().getResource("/resources/images/pieces/blank.png"));
ImageIcon icon = new ImageIcon(img);
// update UI
} catch (IOException exp) {
exp.printStackTrace();
// Probably show a message and exit...
}
Bonus issue:
Without seeing Piece
, it's possible that you are not providing appropriate size hints or adding anything to it or using a null
layout...or something else that we can't identify...