Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMenuItem question

 
Shane Roylance
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two menus, one is a JMenu, and one is a JPopupMenu. They both have basically the same options. I, being very naive, thought I could use one set of JMenuItems for both menus. This works fine, except when I first bring up my popup menu the items disappear from the regular menu. Could someone please explain why this happens? Is there any way to reuse my menu items in this way, or do I need to go with a set for each menu?
My code looks something like this:

Thanks
Shane
 
kevin bennett
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing more code I'm guessing that you are only creating one instance of the menu items. If this is the case then I believe they should disappear from the first menu when added to the second menu. Maybe try adding a Factory method to create specific instances of the menu items, then you will have the same menu items class but different instances. Hope that helps, not sure if I'm being clear.
-Kevin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic