I need to display an image in a JPanel, but this image needs to be in a relative folder (my res folder) in my project path, so that my program can work on any machine, and the images are always available. The code I have for this so far is:
try {
BufferedImage image = ImageIO.read(new File("res/circle.jpg"));
JLabel picLabel = new JLabel(new ImageIcon(image));
panel2.add(picLabel);
picLabel.setLocation(220, 180);
picLabel.setSize(100, 100);
} catch (IOException e1) {
e1.printStackTrace();
}
This code is reading the error "Can't read input file!" and I cant figure out what I'm doing wrong.
(my res folder is located in the src folder of the project)