Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change resource folder?

Java by default looks for files in the project eg. I create a project called calculator and want a background image, I would put the required images in the project folder. I would like it to be tidier by changing where Java looks for the images.

I have created a folder called res and added it to the build path but if I put an image into this res folder it would not find it. For example:

launcher.setIconImage(new ImageIcon("Logo.png").getImage());  

It would not change the IconImage if I put Logo.png in the res folder and would if i put it in the project folder. When I say project folder I mean the folder eclipse creates when you create a new Java project.

like image 395
genfy Avatar asked Dec 19 '13 16:12

genfy


People also ask

What should be in resources folder?

The Resources folder in Figure 1 contains folders for storing binary files, data files, image files, and Include and Library folders that are used to store code used by external functions. The Resources folder can contain more or less folders.

What is resource folder in Android?

The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc.

What is Mac resources folder?

An application's Resources folder provides a rich and varied collection of materials. Here, you'll find such diverse offerings as audio files, icons, window layouts, and more. Practically any kind of file can appear in an application's Resources folder.


2 Answers

The "project folder" is just the folder your program is started in. So when you run your program from eclipse,it looks for the file "Logo.png" in the root directory of the project.

On the other hand, if you export your program and you run it in an other folder, this folder ist the root folder of your program and the PNG will be searched there.

If you want your files in the res folder, you have to reference the PNG accordingly, so for instance you have to write:

launcher.setIconImage(new ImageIcon("res/Logo.png").getImage());  

And if you want to make this more generic, you should use some kind of config mechanism that provides you with the right path for your images. So you only have to alter one place when you want to change the foldername.

like image 74
lwi Avatar answered Oct 04 '22 20:10

lwi


Like @lwi said, you should add the folder name to the path of the resource: "res/Logo.png" instead of "Logo.png".

If you want your images to be included in the JAR when you export your program, I suggest you take a look at this question

Make sure that you put your images in a subfolder of your source folder (as explained in this answer).

like image 37
t_over Avatar answered Oct 04 '22 20:10

t_over