File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JMenuItem question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JMenuItem question" Watch "JMenuItem question" New topic

JMenuItem question

Shane Roylance
Ranch Hand

Joined: Aug 29, 2001
Posts: 72
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:

kevin bennett

Joined: Aug 22, 2001
Posts: 15
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.
I agree. Here's the link:
subject: JMenuItem question
It's not a secret anymore!