I'm working on an Eclipse RCP application. Today I experienced some troubles when displaying images in the context menu. What I wanted to do is to add a column to my table containing images of stars for representing a user rating. On Windows, this causes some problems, since the star images are squeezed up on the left corner of the table cell instead of expanding on the whole cell, but I'll solve that somehow. In addition I have a context menu on the table, with an entry called "rate" where again the different stars from 1 to 5 (representing the rating level) are shown, such that the user can click on it for choosing different ratings. That works fine on Windows. Now I switched to Linux (Ubuntu) to see how it works out there, and strangely, the stars in the table cell are layed out perfectly, while the stars on the context menu don't even show up. Rating inside the table cell works http://img187.imageshack.us/img187/4427/starsratingho4.png
我正在研究Eclipse RCP应用程序。今天在上下文菜单中显示图像时遇到了一些麻烦。我想要做的是在我的表格中添加一列,其中包含用于表示用户评级的星星图像。在Windows上,这会导致一些问题,因为星形图像被挤压在表格单元格的左角而不是在整个单元格上展开,但我会以某种方式解决这个问题。此外,我在桌面上有一个上下文菜单,其中有一个名为“rate”的条目,其中再次显示从1到5(代表评级等级)的不同星星,这样用户可以点击它来选择不同的评级。这在Windows上工作正常。现在我切换到Linux(Ubuntu)看看它是如何工作的,奇怪的是,表格单元格中的星星完美地布局,而上下文菜单中的星星甚至都没有显示出来。表格单元内的评级为http://img187.imageshack.us/img187/4427/starsratingho4.png
star images don't show up http://img514.imageshack.us/img514/8673/contextmenuproblemgt1.png
On the context menu I'm using an action class where I'm setting the image descriptor for the star images:
在上下文菜单中,我正在使用一个动作类,我正在设置星形图像的图像描述符:
public class RateAction extends Action {
private final int fRating;
private IStructuredSelection fSelection;
public RateAction(int rating, IStructuredSelection selection) {
super("", AS_CHECK_BOX);
fRating = rating;
fSelection = selection;
setImageDescriptor(createImageDescriptor());
}
/**
* Creates the correct ImageDescriptor depending on the given rating
* @return
*/
private ImageDescriptor createImageDescriptor() {
ImageDescriptor imgDescriptor = null;
switch (fRating) {
case 0:
return OwlUI.NEWS_STARON_0;
case 1:
return OwlUI.NEWS_STARON_1;
case 2:
return OwlUI.NEWS_STARON_2;
case 3:
return OwlUI.NEWS_STARON_3;
case 4:
return OwlUI.NEWS_STARON_4;
case 5:
return OwlUI.NEWS_STARON_5;
default:
break;
}
return imgDescriptor;
}
/*
* @see org.eclipse.jface.action.Action#getText()
*/
@Override
public String getText() {
//return no text, since the images of the stars will be displayed
return "";
}
...
}
Does somebody know why this strange behaviour appears?
有人知道为什么会出现这种奇怪的行为吗?
Thanks a lot.
非常感谢。
(For some strange reason, the images don't appear. Here are the direct URLs: http://img187.imageshack.us/img187/4427/starsratingho4.png http://img514.imageshack.us/img514/8673/contextmenuproblemgt1.png)
(由于一些奇怪的原因,图像不会出现。以下是直接网址:http://img187.imageshack.us/img187/4427/starsratingho4.png http://img514.imageshack.us/img514/8673/ contextmenuproblemgt1.png)
//Edit: I did some tries and it seems as if the images just don't appear when using a Checkbox style for the context menu (see constructor of the RateAction). When I switched to a PushButton style, the images appeared, although not correctly scaled, but at least they were shown.
//编辑:我做了一些尝试,看起来好像在上下文菜单中使用Checkbox样式时没有出现图像(参见RateAction的构造函数)。当我切换到PushButton样式时,图像出现了,虽然没有正确缩放,但至少它们被显示出来了。
3 个解决方案
#1
When SWT-images have not shown up for me it has been because:
当SWT图像没有显示给我时,原因是:
- I've used capital letters in the image filename, but not in the source code. Works on Windows, not Linux.
- I've tried to run a x64 version of SWT before it was supported.
- I've used VNC. Not sure why it doesn't work, color depth problems?
- I've used Ubuntu. The images have shown up fine with Red Hat.
我在图像文件名中使用了大写字母,但在源代码中没有。适用于Windows,而不适用于Linux。
我曾尝试在支持之前运行x64版本的SWT。
我用过VNC。不确定为什么它不起作用,颜色深度问题?
我用过Ubuntu。 Red Hat的图像显示得很好。
Not sure if this will help you in anyway, but it could perhaps give you a hint where to look.
不管怎么说这不会对你有所帮助,但它可能会给你一个暗示在哪里看。
#2
Maybe this is simply a bug, in which case there would be no real answer to your question.
也许这只是一个错误,在这种情况下你的问题没有真正的答案。
Look if someone has had a similar problem before in Eclipse Bugzilla
看看Eclipse Bugzilla之前是否有类似的问题
Otherwise, try to make a test case as small as possible that works in Windows but not in Linux (or the other way around) and submit a new bug.
否则,尝试使一个尽可能小的测试用例在Windows中运行,但不能在Linux(或其他方式)中运行,并提交一个新的bug。
#3
You can enable icons in menus in your Gnome configuration:
您可以在Gnome配置中的菜单中启用图标:
- Open a terminal
- Run gnome-appearance-properties
- Select Interface tab
- Enable Show icons in menus check box
打开终端
选择接口选项卡
启用菜单中的显示图标复选框
Now you can see icons in your RCP menus.
现在,您可以在RCP菜单中看到图标。
See this Eclipse Bug for details: Bug 293720 - [GTK2.18] Menu icons missing
有关详细信息,请参阅此Eclipse Bug:错误293720 - [GTK2.18]缺少菜单图标
#1
When SWT-images have not shown up for me it has been because:
当SWT图像没有显示给我时,原因是:
- I've used capital letters in the image filename, but not in the source code. Works on Windows, not Linux.
- I've tried to run a x64 version of SWT before it was supported.
- I've used VNC. Not sure why it doesn't work, color depth problems?
- I've used Ubuntu. The images have shown up fine with Red Hat.
我在图像文件名中使用了大写字母,但在源代码中没有。适用于Windows,而不适用于Linux。
我曾尝试在支持之前运行x64版本的SWT。
我用过VNC。不确定为什么它不起作用,颜色深度问题?
我用过Ubuntu。 Red Hat的图像显示得很好。
Not sure if this will help you in anyway, but it could perhaps give you a hint where to look.
不管怎么说这不会对你有所帮助,但它可能会给你一个暗示在哪里看。
#2
Maybe this is simply a bug, in which case there would be no real answer to your question.
也许这只是一个错误,在这种情况下你的问题没有真正的答案。
Look if someone has had a similar problem before in Eclipse Bugzilla
看看Eclipse Bugzilla之前是否有类似的问题
Otherwise, try to make a test case as small as possible that works in Windows but not in Linux (or the other way around) and submit a new bug.
否则,尝试使一个尽可能小的测试用例在Windows中运行,但不能在Linux(或其他方式)中运行,并提交一个新的bug。
#3
You can enable icons in menus in your Gnome configuration:
您可以在Gnome配置中的菜单中启用图标:
- Open a terminal
- Run gnome-appearance-properties
- Select Interface tab
- Enable Show icons in menus check box
打开终端
选择接口选项卡
启用菜单中的显示图标复选框
Now you can see icons in your RCP menus.
现在,您可以在RCP菜单中看到图标。
See this Eclipse Bug for details: Bug 293720 - [GTK2.18] Menu icons missing
有关详细信息,请参阅此Eclipse Bug:错误293720 - [GTK2.18]缺少菜单图标