随便写一下,方便以后查看
1.菜单栏中的快捷方式
2,使用setAccelerator(int acc)方法创建
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Gantt Chart - Group Example");
shell.setSize(600, 500);
shell.setLayout(new FillLayout());
// menu
Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu);
//1种,通过alt+Y调用
MenuItem item = new MenuItem(menu, SWT.CASCADE);
item.setText("mainItem(&Y)");
Menu dropmenu = new Menu(shell, SWT.DROP_DOWN);
item.setMenu(dropmenu);
MenuItem subitem = new MenuItem(dropmenu, SWT.BORDER);
//2种通过 ctrl+shift+f
subitem.setText("sub(&N) Ctrl+SHIFT+F");
subitem.setAccelerator(SWT.CTRL + SWT.SHIFT + 'F');
//1种,通过O,此处你设置什么就能用什么调用,如果设置为小写o,访问用o,不用加alt
//subitem.setText("sub(&O)");
subitem.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e)
{
System.out.println("test tttttttttttttttttt");
FileDialog file = new FileDialog(new Shell());
file.open();
}
@Override
public void widgetDefaultSelected(SelectionEvent e)
{
// TODO Auto-generated method stub
}
});