8024329: [macosx] JRadioButtonMenuItem behaves like a checkbox when using the ScreenMenuBar
authorpchelko
Fri, 11 Oct 2013 18:04:45 +0400
changeset 21252 74ea5712880f
parent 21251 bf72e65e6f91
child 21253 a1e6716bbcbe
8024329: [macosx] JRadioButtonMenuItem behaves like a checkbox when using the ScreenMenuBar Reviewed-by: anthony, serb
jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java
--- a/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java	Fri Oct 11 17:57:50 2013 +0400
+++ b/jdk/src/macosx/classes/com/apple/laf/ScreenMenuItemCheckbox.java	Fri Oct 11 18:04:45 2013 +0400
@@ -93,9 +93,9 @@
         }
 
         if (fMenuItem instanceof JCheckBoxMenuItem) {
-            setState(((JCheckBoxMenuItem)fMenuItem).isSelected());
+            forceSetState(fMenuItem.isSelected());
         } else {
-            setState(fMenuItem.getModel().isSelected());
+            forceSetState(fMenuItem.getModel().isSelected());
         }
     }
 
@@ -196,10 +196,10 @@
 
             switch (e.getStateChange()) {
                 case ItemEvent.SELECTED:
-                    setState(true);
+                    forceSetState(true);
                     break;
                 case ItemEvent.DESELECTED:
-                    setState(false);
+                    forceSetState(false);
                     break;
             }
         }
@@ -210,4 +210,20 @@
             ((CCheckboxMenuItem)peer).setIsIndeterminate(indeterminate);
         }
     }
+
+    /*
+     * The CCheckboxMenuItem peer is calling setState unconditionally every time user clicks the menu
+     * However for Swing controls in the screen menu bar it is wrong - the state should be changed only
+     * in response to the ITEM_STATE_CHANGED event. So the setState is overridden to no-op and all the
+     * correct state changes are made with forceSetState
+     */
+
+    @Override
+    public synchronized void setState(boolean b) {
+        // No Op
+    }
+
+    private void forceSetState(boolean b) {
+        super.setState(b);
+    }
 }