The moose likes Swing / AWT / SWT and the fly likes Right-Click on JMenuItem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Right-Click on JMenuItem" Watch "Right-Click on JMenuItem" New topic

Right-Click on JMenuItem

Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
Hi. I have a JMenuItem that gets added to a JMenu and I'd like to add a popup menu that gets displayed when I right-click on the menu item (and the underlying menu still stays visible), and when I left-click on the menu, it performs its normal action. Does anyone know how to do this?

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

I spent a little bit of time with this tonight. Couldn't get it perfect, but maybe this will get you started:

GenRocket - Experts at Building Test Data
Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
Hi Gregg. I appreciate the start on this code. I think some of that popup code will be useful, but I think I may need to create my own MenuUI. I was doing some digging to find out where the mouse events are processed and it appears to be in the BasicMenuUI. So, I think I have one of two options: either remove the mouse listeners from the menu that already exist and then add my own (but I think this might be a little risky since who knows what other mouse listeners are on the menu item) or create my own MenuUI.

I'm thinking this is not such a simple problem (while I do a lot of Swing programming, creating my own UI classes such as this is not something I do often). Thanks for the help.

jQuery in Action, 2nd edition
subject: Right-Click on JMenuItem
Similar Threads
keep the JMenu from closing the pop up of JMenuItems
How to implement collapse on select in JMenu with JRadioButton as items´╝č
Popup Menu
Urgent - pls help
JMenuItem: Not allowing Mouse Right Click to function on JMenuItem.