【发布时间】:2014-05-31 00:04:10
【问题描述】:
如何将自定义图像添加到 Eclipse SWT,我尝试使用 ImageDescriptor。但我可能做错了什么。
private Action stopAction;
stopAction.setText("Stop");
stopAction.setToolTipText("Stop running");
stopAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
ImageDescriptor imgDesc = null;
try {
imgDesc = ImageDescriptor.createFromURL(new URL("icons/stop.png"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
stopAction.setImageDescriptor(imgDesc);
【问题讨论】:
-
你有异常吗?结果是什么?期望的结果是什么?
-
@Baz 异常是这样的:java.net.MalformedURLException: no protocol: icons/stop.png 期望的结果是获取自定义图像到按钮,所以使用这个 stopAction.setImageDescriptor(PlatformUI.getWorkbench() .getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));我使用下面的代码在图标中加载位于同一项目中的自定义图像
标签: java image url eclipse-plugin swt