0

How can I add action listener for JMenu (not for JMenuItem)? I want to open new window on clicking this menu. Thank you very much!

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user3649515
  • 199
  • 7
  • 17
  • [Read the documentation](http://docs.oracle.com/javase/7/docs/api/javax/swing/JMenu.html): Take a look at the section named ***Methods inherited from class javax.swing.AbstractButton*** – BackSlash Jul 16 '14 at 13:10
  • Have u tried with add mouse listener. ?http://docs.oracle.com/javase/7/docs/api/javax/swing/JMenu.html#addMenuListener(javax.swing.event.MenuListener) – Kishan Bheemajiyani Jul 16 '14 at 13:32

1 Answers1

2

You can try this one and you can add an action listener to the JMenu.

menu.addActionListener(new ActionListener() 
{
    public void actionPerformed(ActionEvent e)
    {
        //Execute when JMenu is pressed
        System.out.println("You clicked the JMenu");
    }
});
Dan
  • 7,286
  • 6
  • 49
  • 114
Kishan Bheemajiyani
  • 3,429
  • 5
  • 34
  • 68