Window popping twice on one click
I have a JMenuBar with a JMenu on it. In this JMenu is a JMenuItem namedabout. The idea is that you click that about and a window will pop up giving details.
Now I have a class which extends JFrame and when you click the about JMenuItem that class is instanciated. The problem is that it's called twice. For some reason a duplicate ActionEvent is being fired when you click the about JMenuItem. Any ideas what could be causing this? I would be happy to e-mail my code to anyone that would like to help.
Thanks,
Brian
> Yeah I'm sure that I haven't. It seems that every
> JMenuItem is firing two ActionEvents to one click.
It's of course easy to test your theory. Add this at the top of your actionPerformed method:
public void actionPerformed(ActionEvent e) {
System.out.println(System.identityHashCode(e));
....
}
That will tell you if indeed two separate ActionEvents are sent, or if it is the same event that is sent to multiple listeners.
Very strange. I seemed to have solved the problem by moving some code around.
I have a class that sets up the menu bar, the constructor called a method that did addActionListener statements to all items. When I moved the addActionListener statements to the constructor it seemed to fix it.
Thanks for that code Torgil.