Reputation: 1890
I'm trying to create a (very) simple GUI program which allows the user to select from different radio buttons to display an image in a JLabel. The code I'm using is this:
JLabel imageLabel = new JLabel();
imageLabel.setIcon(new ImageIcon("images/Dog"));
My question is, where do I put this "images" folder? When I put it in the src and the bin folder, the images still didn't load. I ended up trying the following code which worked when I used the bin folder:
imageLabel.setIcon(new ImageIcon(getClass().getResource("images/Dog")));
The problem is, from what I understand the bin folder isn't supposed to be used for these files? Also, I'm pretty sure the images folder I put in there got deleted (which would be a pretty good reason not to use it...).
I'm sending the directory to my professor, so I don't want the file path to work exclusively on my computer.
PS I'm using Eclipse, if that matters.
Upvotes: 4
Views: 4285
Reputation: 59283
Just put it in the project's folder. Example:
You would put your images
folder where my "del_icon
" image is. Just right in the folder.
Upvotes: 3