简体   繁体   中英

SWT popup menu shortcut not working

I am creating an Eclipse plugin and using the SWT popup menu (context menu) for one of the controls in plugin. The context menu item works, but the accelerator (shortcut) that I set for the menu item has no effect and it does not work. I create the menuitem like this:

MenuItem parent = new Menu(getShell(), SWT.POP_UP);
MenuItem menuItem = new MenuItem(parent, SWT.PUSH);
menuItem.setText("Click me");
menuItem.setAccelerator( SWT.CTRL+ 'F');

Note that the shortcut problem occurs for the POP_UP menu, not the BAR menu item.

Try item.setAccelerator(SWT.MOD1 + 'A');

MOD1, MOD2 .. MOD4 are the keyboard and/or mouse event mask indicating that the MOD1 key was pushed on the keyboard when the event was generated.

More references here and there .

If you are developing an Eclipse plugin, and you are putting the menu on a View , then it is possible that the Eclipse Platform shortcut system is interfering with your SWT component's accelerator.

I suggest you refactor your code, so that you use the shortcuts that Eclipse provides.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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