Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8024329

[macosx] JRadioButtonMenuItem behaves like a checkbox when using the ScreenMenuBar

    Details

    • Subcomponent:
    • Resolved In Build:
      b115
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      java version " 1.7.0_12-ea "
      Java(TM) SE Runtime Environment (build 1.7.0_12-ea-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 24.0-b25, mixed mode)
      AND
      java version " 1.7.0_10-ea "
      Java(TM) SE Runtime Environment (build 1.7.0_10-ea-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X 10.8.2

      A DESCRIPTION OF THE PROBLEM :
      When using multiple JRadioButtonMenuItems in a ButtonGroup with the ScreenMenuBar enabled it is possible to unselect the currently selected one by clicking on it. This fires the ActionListener and the menu item displays as deselected even though it is still selected.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the provided TestFrame and click on the menu item " One " multiple times.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The menu item should stay looking selected since it s a radion button in a buttongroup.
      ACTUAL -
      The menu item toggles from being selected to unselected and back again even though the selection state of the JRadioButtonMenuItem never changes.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Toolkit;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.KeyEvent;
      import java.lang.reflect.InvocationTargetException;

      import javax.swing.ButtonGroup;
      import javax.swing.JCheckBoxMenuItem;
      import javax.swing.JFrame;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;
      import javax.swing.JRadioButtonMenuItem;
      import javax.swing.KeyStroke;
      import javax.swing.SwingUtilities;


      public class TestFrame extends JFrame {

      public TestFrame() {
      JMenuBar menuBar = new JMenuBar();
      JMenu fileMenu = new JMenu( " File " );

      final JMenuItem itemOne = new JRadioButtonMenuItem( " One " );
      itemOne.addActionListener(new ActionListener() {
      @Override public void actionPerformed(ActionEvent e) {
      System.out.println( " One chosen: " + itemOne.isSelected());
      }
      });
      fileMenu.add(itemOne);
      itemOne.setSelected(true);

      final JMenuItem itemTwo = new JRadioButtonMenuItem( " Two " );
      itemTwo.addActionListener(new ActionListener() {
      @Override public void actionPerformed(ActionEvent e) {
      System.out.println( " Two chosen: " + itemTwo.isSelected());
      }
      });
      fileMenu.add(itemTwo);
      ButtonGroup group = new ButtonGroup();

      group.add(itemOne);
      group.add(itemTwo);

      menuBar.add(fileMenu);
      setJMenuBar(menuBar);
      pack();
      setVisible(true);
      }

      public static void main(String[] args) throws InvocationTargetException, InterruptedException {
      System.setProperty( " apple.laf.useScreenMenuBar " , " true " );
      SwingUtilities.invokeAndWait(new Runnable() {
      @Override public void run() {
      new TestFrame();
      }
      });
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      This issue goes away if you don't use the ScreenMenuBar.

        Attachments

          Activity

            People

            • Assignee:
              alexsch Alexandr Scherbatiy
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: