views:

1207

answers:

3

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.

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.

A: 

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

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.

eljenso
+1  A: 

When SWT-images have not shown up for me it has been because:

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

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

Kire Haglin
A: 

You can enable icons in menus in your Gnome configuration:

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

See this Eclipse Bug for details: Bug 293720 - [GTK2.18] Menu icons missing

Daniel Murygin