1

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

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)

//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.

4

3 回答 3

1

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

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

不确定这是否会对您有所帮助,但它可能会提示您在哪里查看。

于 2008-12-31T09:18:50.107 回答
0

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

  • 打开终端
  • 运行gnome-appearance-properties
  • 选择接口选项卡
  • 启用在菜单中显示图标复选框

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

有关详细信息,请参阅此 Eclipse 错误: 错误 293720 - [GTK2.18] 缺少菜单图标

于 2010-07-29T09:52:32.930 回答
0

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

看看是否有人以前在Eclipse Bugzilla中遇到过类似的问题

否则,请尝试使测试用例尽可能小,在 Windows 中有效,但在 Linux 中无效(或相反)并提交新错误。

于 2008-12-30T09:58:04.443 回答