import java.awt.Menu; import java.awt.MenuBar; import java.awt.MenuItem; import java.awt.MenuShortcut; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JOptionPane; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author ampopov */ public class MenuTest extends JFrame{ public MenuTest() { MenuBar mb = new MenuBar(); Menu menu = new Menu("Menu"); MenuItem m = new MenuItem("My menu"); menu.add(m); m.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(rootPane, "Menu activated"); } }); MenuShortcut s = new MenuShortcut(KeyEvent.VK_M, false); m.setShortcut(s); mb.add(menu); setMenuBar(mb); } public static void main(String[] args) { JFrame f = new MenuTest(); f.setDefaultCloseOperation(EXIT_ON_CLOSE); f.setSize(300,300); f.setVisible(true); } }