我想在 java 中添加快捷方式 JUST DELETE

I want to add Shortcut JUST DELETE in java

NOTEPAD.

NOTEPAD I made.

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

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);

试试这个:

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

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

还有另一种选择

menuItem.setMnemonic('F');

如果您在 运行 您的程序

时按 ALT+F,这将起作用

仅供删除使用

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