【问题标题】:Eclipse RCP and JFace: Problems with Images in Context menu and TreeViewerEclipse RCP 和 JFace:上下文菜单和 TreeViewer 中的图像问题
【发布时间】: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


    【解决方案1】:

    当我没有显示 SWT 图像时,是因为:

    • 我在图像文件名中使用了大写字母,但在源代码中没有。适用于 Windows,而非 Linux。
    • 我曾尝试在 SWT 受支持之前运行它的 x64 版本。
    • 我使用过 VNC。不知道为什么它不起作用,颜色深度问题?
    • 我用过 Ubuntu。图像在 Red Hat 中显示良好。

    不确定这是否会对您有所帮助,但它可能会给您一个提示。

    【讨论】:

      【解决方案2】:

      也许这只是一个错误,在这种情况下,您的问题将没有真正的答案。

      看看有没有人在Eclipse Bugzilla之前遇到过类似的问题

      否则,请尝试制作一个在 Windows 中有效但在 Linux 中无效(或相反)的测试用例尽可能小,然后提交一个新错误。

      【讨论】:

        【解决方案3】:

        您可以在 Gnome 配置中启用菜单中的图标:

        • 打开终端
        • 运行 gnome-appearance-properties
        • 选择界面标签
        • 启用在菜单中显示图标复选框

        现在您可以在 RCP 菜单中看到图标。

        查看这个 Eclipse Bug 了解详情:Bug 293720 - [GTK2.18] Menu icons missing

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-04-01
          • 2017-05-13
          • 1970-01-01
          • 2011-08-12
          • 1970-01-01
          • 2016-08-14
          • 2010-10-24
          • 2015-10-06
          相关资源
          最近更新 更多