I’m new to Java and I want to add a background image to a Composite. I can only use SWT, no JFace. I’m using eclipse indigo IDE (3.8) and when I want to set a background image, first I initialize an Image class to an image object, but when I press CTRL + SPACE to help choosing the constructor, I have 5 different constructors. I don’t know what to choose.
I must use a relative path. The package has the following structure:
org.mypackage.program //the package name
org.mypackage.program/src/org.mypackage.program //the plugin-project automated created classes
org.mypackage.program/src/views // all views
org.mypackage.program/car_image.jpg // the image what I would set in background
org.mypackage.program/views/View.java // the class where I want to set the background
This is what I made, but it’s not working:
Image image = new Image(Display.getCurrent(), this.getClass().getClassLoader().getResource("car_image.jpg"));
compImage.setBackgroundImage(image);
I’m new to OOP too, I programmed only structured/module programs.
please try below code:-
Please note, how the relative path is mentioned
.\\src\\org\\mypackage\\program\\car_image.gifHere src is the root folder of application.