我刚接触Java,想在一个组合框中添加背景图片。我只能使用SWT,不能用JFace。我正在使用eclipse indigo IDE (3.8),当我想设置背景图片时,首先我将Image类初始化为一个图像对象,但是当我按下CTRL + SPACE以帮助选择构造函数时,有5个不同的构造函数可供选择。我不知道该选择哪一个。
我必须使用相对路径。包具有以下结构:
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
这是我做的东西,但它没有起作用:
Image image = new Image(Display.getCurrent(), this.getClass().getClassLoader().getResource("car_image.jpg"));
compImage.setBackgroundImage(image);
我也是OOP的新手,之前只写过结构化/模块化程序。