I am implementing menus using JMenu. I have recently encountered a problem that I don't know how to resolve. I have 2 menus that happen to have the same named JMenuItem. In order to resolve this I need to determine which JMenu the JMenuItem came from. However, I don't see how to determine that from what is available in the ActionEvent object. What am I missing? TIA.
That was what I was thinking. Each JMenu has to have its own ActionPerformed method. Its probably easier for me to just avoid duplicating JMenuItems buy altering the names slightly. Thanks.
FYI, JMenu using=(JMenu) SwingUtilities.getAncestorOfClass(getClass(), source); will try to find an ancestor component of this class. If you want a JMenu, replace getClass() with JMenu.class (the Class object for JMenu).
But I agree that a separate ActionListener (or even better - Action) is a much cleaner solution.
Post by:autobot
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
a bit of art, as a gift, that will fit in a stocking