Question

Hey So I'm pretty much awful at java and I want to add a ImageIcon now I've done this before and I even have the images to work the only issue is the program I am making is for University work and when I submit the work it will be submitted online through a .rar file.

So my issue is currently the image's have a huge direct path so i.e.

C:\Users\MY-NAME\Documents\NetBeansProjects\UNI-PROJECT\src\IMAGES\image.png

Since they will be reviewing my work on their work PC or home PC whatever the images wont work for them since it's using my home reference. How can I reference a image so they can open it where ever and the images will still work?

Thanks in advance

-SKENG-

Was it helpful?

Solution

The Java Tutorial on How to Use Icons has a small section explaining how to use Class#getResource() when the image is included with the application - look at the createImageIcon() method and the description that follows it.

OTHER TIPS

You can put your images in the current folder or subfolders and then use the following path (for example):

System.getProperty("user.dir") + "images\pic1.gif"

Simply do not use absolute path, and put the images into a subdirectory where is located your sources or binaries.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top