简体   繁体   English

如何通过右键单击GUI中的特定对象来添加菜单? (在Eclipse RCP中)

[英]How to add a menu by Right clicking a particular object in the GUI? (In Eclipse RCP)

I wanted to add a right click menu, by selecting a column in my GUI. 我想通过在GUI中选择一列来添加右键菜单。

Any suggestions how to do it? 有什么建议怎么做吗?

啊哈,我想您需要在您的GUI的一部分中放置一个鼠标事件侦听器,以响应鼠标事件,例如,鼠标单击...对于菜单,您需要的是JPopupMenu ...,只是一个想法!

You are talking about actions(?). 您正在谈论动作(?)。 Check Platform Plug-in Developer Guide > Programmer's Guide > Plugging into the workbench > Basic workbench extension points using actions. 查看平台插件开发人员指南>程序员指南>插入工作台>使用操作插入基本工作台扩展点。

If you're looking for solution to Tree or Table, here is an example: 如果您正在寻找Tree或Table的解决方案,请参考以下示例:

    final Menu menu = new Menu(tracksTree);
    tracksTree.setMenu(menu);
    menu.addMenuListener(new MenuAdapter() {
        @Override public void menuShown(MenuEvent e) {

            MenuItem[] items = menu.getItems();
            for (int i = 0; i < items.length; i++) {
                items[i].dispose();
            }

            TreeItem[] selection = tracksTree.getSelection();
            if (selection.length > 0) {
                TreeItem selectedItem = selection[0];
                System.out.println(selectedItem.getData());


            }
        }

        @Override public void menuHidden(MenuEvent e) {

        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM