Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Navigating menu hierarchy in a JPopupMenu

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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
  • 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
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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.
 
The airline is called "Virgin"? Don't you want a plane to go all the way? This tiny ad will go all the way:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic