I have added an action to itemMenu using the setAction method below, but when I execute the code, the text of this menu item disappears. The code works fine, since clicking in the location of this menu item causes the action to be executed.
exit.setAction(new AbstractAction() {
public void actionPerformed(ActionEvent event) {
System.exit(0);
}
}
Pass in the name of the button or menu item to the constructor of the action: