如何禁用 JFace 菜单的所有图像,但在工具栏中保留它们启用状态

发布于 2024-07-17 06:26:39 字数 158 浏览 6 评论 0原文

如果我创建一组要在 JFace 应用程序中使用的操作,并将图像分配给这些操作,那么这些图像会同时显示在工具栏(我想要它们的位置)和菜单(我不想要它们的位置)中。

除了提供两组完全独立的操作(这首先消除了部分操作点)之外,我怎样才能安排这些图像仅显示在工具栏中,并且让菜单仅显示文本?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜`诱少女 2024-07-24 06:26:39

我也遇到了这个问题(除了我想要工具栏和菜单使用不同的文本。)我最终使用了相同的操作,但它的两个不同的实例。

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

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

或者,您可以将图像描述符存储在工具栏版本的操作中,并将其设置为菜单版本的 null。

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.

静谧 2024-07-24 06:26:39

我自己还没有检查过这一点,但看了一下这个方法:

public int getStyle() { ... }

它是在 Action 类中定义的,并且它似乎返回 Action 以图形方式表示的界面元素的类型。 那么你可以重写 getImageDescriptor() 方法:

public ImageDescriptor getImageDescriptor() {
    if (getStyle() == AS_DROP_DOWN_MENU)
        return null; // No icon in a menu
    return someImageDescriptor; // Actual icon
}

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
}
不再让梦枯萎 2024-07-24 06:26:39

我最终基本上重复了这些动作,配对,一个有图像,一个没有,从而从一开始就消除了动作的好处(叹气)。 另一方面,由于每个操作仅调用控制器中的单个方法来执行工作,因此它并不太阴险,并且将这些对组合在一起可以使发生的情况变得相当清晰。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文