• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Navigating menu hierarchy in a JPopupMenu

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
mdahmus@io.com
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mike Dahmus
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic