我想在java中添加Shortcut JUST DELETE

时间:2016-09-13 07:22:18

标签: java awt notepad

NOTEPAD.

NOTEPAD I made.

我如何在第9行添加MenuShortcut JUST DELETE? Plz帮助我......

ms[0] = new MenuShortcut(KeyEvent.VK_N);
ms[1] = new MenuShortcut(KeyEvent.VK_O);
ms[2] = new MenuShortcut(KeyEvent.VK_S);
ms[3] = new MenuShortcut(KeyEvent.VK_P);
ms[4] = new MenuShortcut(KeyEvent.VK_Z);
ms[5] = new MenuShortcut(KeyEvent.VK_X);
ms[6] = new MenuShortcut(KeyEvent.VK_C);
ms[7] = new MenuShortcut(KeyEvent.VK_V);
ms[8] = new MenuShortcut(KeyEvent.VK_DELETE);
ms[9] = new MenuShortcut(KeyEvent.VK_F);
ms[10] = new MenuShortcut(KeyEvent.VK_F3);
ms[11] = new MenuShortcut(KeyEvent.VK_H);
ms[12] = new MenuShortcut(KeyEvent.VK_G);
ms[13] = new MenuShortcut(KeyEvent.VK_A);
ms[14] = new MenuShortcut(KeyEvent.VK_F5);

1 个答案:

答案 0 :(得分:0)

试试这个:

menuItem.setAccelerator(KeyStroke.getKeyStroke(
    java.awt.event.KeyEvent.VK_S, 
    java.awt.Event.CTRL_MASK));

其中VK_S是您想要的密钥,CTRL_MASK是控制密钥。

使用

还有另一种选择
menuItem.setMnemonic('F');

如果您在运行程序时按ALT + F

,这将有效

仅供DELETE使用

jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0));