Java GUI not loading images/ImageIcons help
Hey, so im going through the basics of GUI. At first it was going great but right now Ive been trying to a) set the ImageIcon of the frame and also setting the ImageIcon of a label but with my current implementation none of the pictures load and I dont know why. I have included both the code and the file strucutre (ps. i have also set the Pictures package to be Resources Root Directory):
5 Replies
⌛
This post has been reserved for your question.
Hey @mjstx! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
place images in resources folder, then load them using getResource() or you can use relative path referencing "/Pictures " uses absolute referencing and tries to locate /Pictures from the root file system
alr wait ill give it a try
still no luck
could you type what you meant
like
ImageIcon img = new ImageIcon(Main.class.getResource("/Pictures/yippee.jpg"));
if Pictures is your resources root folder, do like this
ImageIcon img = new ImageIcon(Main.class.getResource("yippee.jpg"));
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.