Amit.D
Amit.D

Reputation: 113

loading an image from resources folder using relative path

How to set the images in background of shell using relative path. I have image which resides in folder "res". I am adding screen shot here, just you to have better understanding of 'directory structure' as well as my question(in case if it seemed little ambiguous to you). Any suggestion and help will be appreciated.enter image description here

Upvotes: 1

Views: 2216

Answers (2)

Sanjeev
Sanjeev

Reputation: 9946

In order to read your images from resources folder, you need to :

add res folder to classpath

locate file absolutely, i.e. "/res/SplashWindow.jpg"

Hope this helps

Upvotes: 1

icza
icza

Reputation: 417642

The SplashWindow.jpg is placed next to the class notDltNow which you specify as the reference for relative paths, so you can simply write:

shell.setBackgroundImage(SWTResourceManager.getImage(
    notDltNow.class, "SplashWindow.jpg"));

It is also a good idea to put resources inside the src folder so when you export your code e.g. into a jar, the resources will also be exported and still available to the code without additional hassle.

Upvotes: 2

Related Questions