Hi all, I'm trying to use one ActionListener for a large popup menu which can be dynamically modified by my customer classes; i.e., I don't necessarily know in advance what will be in there. I can, however, ensure that I get an actionPerformed on each of those menuitems. So, in my actionPerformed, I'm trying to figure out how to navigate the "menu hierarchy" and determine my full "menu path"; i.e., if the user selected "Item 3" in "Submenu 2", I want to be able to go from the menuitem whose text is "Item 3" (which I can get from the event) and find its parent, and find its parents' label. Where I'm stuck right now is determining what the parent's name/label is. I can find the containing submenu for the menuitem; and it's a JPopupMenu (even though when added, it was actually a JMenu); which doesn't seem to have any label or name field which actually functions. It certainly doesn't have the label that I originally gave it ("submenu"). In short: I get an actionPerformed on a menuitem, and I'd like to be able to generate a "fully qualified" menu name, like "Submenu 2->Menuitem 3", specifically WITHOUT having handles on everything in the menu. Any help would be appreciated. Thanks, Mike Dahmus email@example.com
I haven't checked on this, but setActionCommand(String) migth be worth a try. you would have to set for each item its label (+ any parent action commands/labels) as action command. chantal
Joined: Mar 07, 2002
Originally posted by Chantal Ackermann: I haven't checked on this, but setActionCommand(String) migth be worth a try. you would have to set for each item its label (+ any parent action commands/labels) as action command. chantal
Thanks, Chantal! That's exactly what I was looking for and is a great solution to the problem.
subject: Navigating menu hierarchy in a JPopupMenu