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

[550 byte] By [kuriyama@woh.rr.coma] at [2007-10-3 2:26:29]
# 1
just as you said, there may be duplicate calls for it.-Nywled
Redxxiva at 2007-7-14 19:25:32 > top of Java-index,Java Essentials,New To Java...
# 2
Hmm. Let me rephrase the question.How would it be possible that a JMenuItem could fire two ActionEvents on one click?
kuriyama@woh.rr.coma at 2007-7-14 19:25:32 > top of Java-index,Java Essentials,New To Java...
# 3
Make sure you haven't added the same ActionListener twice.
Torgila at 2007-7-14 19:25:32 > top of Java-index,Java Essentials,New To Java...
# 4
Yeah I'm sure that I haven't. It seems that every JMenuItem is firing two ActionEvents to one click.
kuriyama@woh.rr.coma at 2007-7-14 19:25:32 > top of Java-index,Java Essentials,New To Java...
# 5
Well, then maybe it's time to post a short demo program that shows this behavior.
Torgila at 2007-7-14 19:25:32 > top of Java-index,Java Essentials,New To Java...
# 6
how about your event handlers? try to check it.. there may be duplicates
Redxxiva at 2007-7-14 19:25:32 > top of Java-index,Java Essentials,New To Java...
# 7

> 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.

Torgila at 2007-7-14 19:25:32 > top of Java-index,Java Essentials,New To Java...
# 8

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.

kuriyama@woh.rr.coma at 2007-7-14 19:25:32 > top of Java-index,Java Essentials,New To Java...