This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 243270

Summary: Actions.connect fails to update JMenuItem's enabled state in main menu
Product: platform Reporter: ebakke
Component: ActionsAssignee: Jan Peska <JPESKA>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 8.0   
Hardware: PC   
OS: Mac OS X   
Issue Type: DEFECT Exception Reporter:
Attachments: An example Action exhibiting the bug

Description ebakke 2014-03-25 20:43:35 UTC
Created attachment 146317 [details]
An example Action exhibiting the bug

See the attached example.

Actions.connect(JMenuItem, Action, boolean popup) fails to keep the JMenuItem up to date with the state of the Action in the case where popup == false.

The bug seems to be in Actions.MenuBridge.prepare(), where addNotify() is called only if the "popup" parameter is true, based on the assumption that "popups generally get no hierarchy events" (according to a comment in MenuBridge.prepare() ). This is true, but also seems to be true for items in the main menu. Maybe it's a MacOS thing?

With the above understanding of the bug, a workaround is to do "menuItem.putClientProperty("ancestor", new JMenu("FakeMenu"));" after invoking Actions.connect. But it would be nice to have this fixed in general.

Proposed fix: call addNotify() regardless of the value of popup in Actions.MenuBridge.prepare().

A possibly related bug: https://netbeans.org/bugzilla/show_bug.cgi?id=70731
Comment 1 Jan Peska 2014-07-14 09:14:53 UTC
Your example works fine on my Windows 7. I'll try to reproduce it on MacOS as you suggested.