Java 在eclipse中创建图像不起作用的按钮
我正在尝试创建一个带有图像的按钮。可以找到API 这是我的密码:Java 在eclipse中创建图像不起作用的按钮,java,eclipse,eclipse-plugin,Java,Eclipse,Eclipse Plugin,我正在尝试创建一个带有图像的按钮。可以找到API 这是我的密码: Button settings = new Button(swpContainer, SWT.PUSH); settings.setText("Settings"); settings.setImage(new Image(null, "/myProject/icons/settings.png")); 这是我得到的一个例外 org.eclipse.swt.SWTException: i/o error (java.io.Fil
Button settings = new Button(swpContainer, SWT.PUSH);
settings.setText("Settings");
settings.setImage(new Image(null, "/myProject/icons/settings.png"));
这是我得到的一个例外
org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: \myProject\icons\settings.png (The system cannot find the path specified))
我右键单击eclipse中的图像并从属性中获取路径。
任何帮助都将不胜感激 假定
myProject
是您的项目名称,icons
是项目中的一个简单文件夹,然后说newimage(null,“icons/settings.png”)代码>就足够了
我还建议:
- 阅读
- 恰当地
假定myProject
是您的项目名称,icons
是项目中的一个简单文件夹,然后说new Image(null,“icons/settings.png”)代码>就足够了
我还建议:
- 阅读
- 恰当地
试试这个:
Button settings = new Button(swpContainer, SWT.PUSH);
settings.setText("Settings");
Image image = new Image(swpContainer.getShell().getDisplay(),
getClass().getClassLoader().getResourceAsStream("icons/settings.png")); //$NON-NLS-1$
settings.setImage(image);
试试这个:
Button settings = new Button(swpContainer, SWT.PUSH);
settings.setText("Settings");
Image image = new Image(swpContainer.getShell().getDisplay(),
getClass().getClassLoader().getResourceAsStream("icons/settings.png")); //$NON-NLS-1$
settings.setImage(image);
如果您是为RCP应用程序编写它,请尝试使用ImageDescriptor并创建图像
Image IMG_EXAMPLE = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
"/icons/settings.png").createImage();
如果您是为RCP应用程序编写它,请尝试使用ImageDescriptor并创建图像
Image IMG_EXAMPLE = AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID,
"/icons/settings.png").createImage();