You have to use setAccelerator()
method for JMenuItem
:
close.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK ));
From Javadoc:
JMenuItem#setAccelerator(KeyStroke)
Sets the key combination which invokes the menu item's action listeners without navigating the menu hierarchy. It is the UI's responsibility to install the correct action. Note that when the keyboard accelerator is typed, it will work whether or not the menu is currently displayed.
Additional note:
Replace
LookAndFeelInfo
toUIManager.LookAndFeelInfo
as it's an inner class insideUIManager
.Call the constructor in the main method.
Change the parameter of
setDefaultCloseOperation(1)
to 3 as3 = JFrame.EXIT_ON_CLOSE
, but1=JFrame.HIDE_ON_CLOSE
which hides the frame, personally, I hate it, because close button created for closing frame, not hiding it, like Skype.Add actionListener to close button :
close.addActionListener(this);