【发布时间】:2010-09-28 19:51:04
【问题描述】:
我正在开发一个 Eclipse RCP 应用程序。今天我在上下文菜单中显示图像时遇到了一些麻烦。我想要做的是在我的表格中添加一列,其中包含代表用户评分的星星图像。在 Windows 上,这会导致一些问题,因为星形图像被挤压在表格单元格的左角而不是在整个单元格上展开,但我会以某种方式解决这个问题。此外,我在表格上有一个上下文菜单,其中有一个名为“rate”的条目,其中再次显示了从 1 到 5 的不同星星(代表评级级别),以便用户可以单击它来选择不同的评级。这在 Windows 上运行良好。 现在我切换到 Linux (Ubuntu) 看看它是如何工作的,奇怪的是,表格单元格中的星星布局完美,而上下文菜单上的星星甚至没有出现。 Rating inside the table cell works http://img187.imageshack.us/img187/4427/starsratingho4.png
star images don't show up http://img514.imageshack.us/img514/8673/contextmenuproblemgt1.png
在上下文菜单中,我使用了一个动作类,我在其中设置星形图像的图像描述符:
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 "";
}
...
}
有人知道为什么会出现这种奇怪的行为吗?
非常感谢。
(由于某种奇怪的原因,图像没有出现。以下是直接 URL: http://img187.imageshack.us/img187/4427/starsratingho4.png http://img514.imageshack.us/img514/8673/contextmenuproblemgt1.png)
//编辑: 我做了一些尝试,似乎在为上下文菜单使用复选框样式时图像似乎没有出现(请参阅 RateAction 的构造函数)。当我切换到 PushButton 样式时,图像出现了,虽然没有正确缩放,但至少显示出来了。
【问题讨论】:
标签: java image eclipse-rcp contextmenu