This question already has answers here:
JMenu ActionListener
                                
                                    (2个答案)
                                
                        
                5年前关闭。
            
        

如何为JMenu(不是JMenuItem)添加动作监听器?我想在单击此菜单时打开新窗口。非常感谢你!

最佳答案

您可以尝试这一操作,还可以向JMenu添加一个动作侦听器。

menu.addActionListener(new ActionListener()
{
    public void actionPerformed(ActionEvent e)
    {
        //Execute when JMenu is pressed
        System.out.println("You clicked the JMenu");
    }
});

10-06 14:53