How can I disable all images for an JFace menu but leave them enabled in the toolbar

StackOverflow https://stackoverflow.com/questions/734841

  •  09-09-2019
  •  | 
  •  

Question

If I create a set of actions to be used in a JFace application and I assign images to those actions, those images show up in both the toolbar (where I want them) and in the menus (where I don't want them).

Other than supplying two completely separate sets of actions (which eliminates part of the point of actions in the first place), how can I arrange to have those images displayed ONLY in the toolbar, and have the menus display only text?

Was it helpful?

Solution 3

I ended up essentially duplicating the actions, making pairs, one with an image, one without, thereby eliminating the benefit of actions in the first place (sigh). On the other hand, since each action does just invoke a single method in the controller to perform the work, it's not too insidious and grouping the pairs together makes it reasonably clear what's going on.

OTHER TIPS

I ran into this problem as well (except I wanted different text for the toolbar and menu.) I ended up using the same action, but two different instances of it.

// Use this one in the menu
Action a = new Action();

// Use this one in the toolbar
Action a2 = new Action();
a2.setImageDescriptor(img);

Alternately, you could store the image descriptor in the action for the toolbar version and set it to null for the menu version.

I haven't checked this myself, but give this method a looksee:

public int getStyle() { ... }

It's defined in the Action class, and it appears to return the type of interface element that the Action is graphically represented as. So then you could override the getImageDescriptor() method:

public ImageDescriptor getImageDescriptor() {
    if (getStyle() == AS_DROP_DOWN_MENU)
        return null; // No icon in a menu
    return someImageDescriptor; // Actual icon
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top