-3

NOTEPAD.

NOTEPAD I made.

How I add MenuShortcut JUST DELETE in line 9? Plz help me....

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);
Diana
  • 405
  • 1
  • 5
  • 13
  • Are you using an IDE (Netbeans)? – Petros Sep 13 '16 at 07:24
  • @Peter No, I use eclipse. – Diana Sep 13 '16 at 07:32
  • You should add more information on what you are trying to accomplish and the minimum code to replicate your problem (see [here for instructions on that](http://stackoverflow.com/help/mcve)). In your case the code should be create a window and create your menu – baudsp Sep 13 '16 at 07:33
  • @baudsp Oh, sorry. I came here for the first time. I reading this link now. thank you for your kindness! – Diana Sep 13 '16 at 07:48

1 Answers1

0

try this:

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

where VK_S is the the key you want and CTRL_MASK is the control key.

There is another option by using

menuItem.setMnemonic('F');

this will work if you press ALT+F when running your program

for just DELETE use

jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0));
Petros
  • 550
  • 3
  • 13