Eclipse RCP and JFace: Issues with Images in Context Menu and TreeViewer

I am working on an Eclipse RCP application. Today I ran into some problems when displaying images in the context menu. I would like to add a column to my table that contains star images to represent the user's rating. On Windows this causes some problems as star images shrink in the left corner of the table cell rather than expand across the whole cell, but I will somehow resolve that. In addition, I have a context menu in the table, with an entry titled "rate", which again shows different stars from 1 to 5 (representing the rating level) so that the user can click on it to select different ratings. This works great on Windows. I have now switched to Linux (Ubuntu) to see how it works there, and oddly enough, the stars in the table cell are laid out beautifully.and the stars in the context menu are not even displayed. The rating inside the table cell works http://img187.imageshack.us/img187/4427/starsratingho4.png

stellar images not showing http://img514.imageshack.us/img514/8673/contextmenuproblemgt1.png

In the context menu, I am using an action class in which I set the image descriptor for 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 anyone know why this strange behavior is showing up?

Many thanks.

(For some strange reason, the images are not showing. Here are the direct URLs: http://img187.imageshack.us/img187/4427/starsratingho4.png http://img514.imageshack.us/img514/8673/contextmenuproblemgt1. png )

// Edit: I've made a couple of attempts and it seems like the images just aren't showing when using the checkbox style for the context menu (see the RateAction constructor). When I switched to the PushButton style, the images appeared, although they were not properly scaled, but at least they were shown.

+1


source to share


3 answers


When SWT images are not showing for me, it was because:

  • I have used capital letters in the image file name, but not in the original code. Works on Windows, not Linux.
  • I tried to run the x64 version of SWT before it was supported.
  • I have used VNC. Not sure why it doesn't work, color depth issues?
  • I have used Ubuntu. The images showed up well with Red Hat.


Not sure if this will help you anyway, but it might give you a hint where to look.

+1


source


Perhaps this is just a mistake, in which case there will be no real answer to your question.

See if anyone had a similar problem before in Eclipse Bugzilla



Otherwise, try to make as little test case as possible that works on Windows but not Linux (or vice versa) and file a new bug.

0


source


You can enable icons in the menu in the Gnome config:

  • Open terminal
  • Run gnome-appearance properties
  • Select the "Interface" tab
  • Enable display of icons in the menu.

You can now see the icons in the RCP menu.

See this Eclipse Bug for details: Bug 293720 - [GTK2.18] Menu Icons Missing

0


source







All Articles