JDK-8273310 : [macos] Enter key does not perform action associated with menu item using ScreenMenuBar
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8,9,11,15,16,17
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2021-08-31
  • Updated: 2024-12-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25Unresolved
Related Reports
Blocks :  
Relates :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
On Mac OS X with the ScreenMenuBar, navigate menu item by keyboard only: pressing <control> <F2> and arrow keys, then press <enter> key. The action associated with the menu item is not performed.

If the JMenuItem is a JCheckBoxMenuItem, then it would work on JDK 11.0.12 but not on JDK 16.0.2 (currently latest).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run the sample code. 
2. Press <control> <F2> to select the screen menu bar (make sure the check box in System Preferences > Keyboard > Shortcuts > "Move focus to the menu bar" is selected).
3. Press <right> arrow key twice to select the "File" menu
4. Press <down> arrow key twice to select the "Menu Item"
5. Press <enter> key; nothing shows on the console
6. Repeat steps 2-3 above
7. Press <down> arrow key three times to select the "Check Box" menu item
8. Press <enter> key; the word "hello, check box" is shown on the console -- however, this is not working when running with JDK 16

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Step 5: The console should show "hello, menu item"
Step 8: The console should show "hello, check box"
ACTUAL -
Step 4: The console does not show "hello, menu item"
Step 8: The console shows "hello, check box" on JDK 11 but not JDK 16

---------- BEGIN SOURCE ----------
import java.awt.Desktop;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;

public class MenuFrame extends JFrame {
    public MenuFrame() {
        JMenuBar menuBar = new JMenuBar();
        JMenu menu = new JMenu("File");
        
        JMenuItem menuItem = menu.add(new AbstractAction("Menu Item") {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("hello, menu item");
            }
        });
        
        JMenuItem checkBoxItem = menu.add(new JCheckBoxMenuItem(new AbstractAction("Check Box") {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("hello, check box");
            }
        }));
        
        
        menuBar.add(menu);
        setJMenuBar(menuBar);
        
        Desktop.getDesktop().setDefaultMenuBar(menuBar);
    }        
    
    public static void main(String...args) {
        SwingUtilities.invokeLater(() -> {
            MenuFrame editor = new MenuFrame();
            editor.setSize(400, 300);
            editor.setVisible(true);
        });
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Have tried various approaches such as using ActionListener, ActionMap/InputMap, ChangeListener, ItemListener, KeyListener,  MenuKeyListener, PropertyChangeListener, etc. via the JMenuItem/JMenu/JPopupMenu classes, but no luck.

FREQUENCY : always



Comments
This is an aftereffect of JDK-8152492 to restrict doublekey events which was made more strict by Manajit's fix JDK-8216971.
09-09-2021

[~vdyakov] This is reproduced on Oracle JDKs OS: Mac BigSur version 11.2.3 JDK 11.0.12 :Partial Pass Output: The console shows "hello, check box" but does not shows "hello, menu item" when using keyboard shortcuts <control> <F2>, then pressing arrow key to select Menu Items.
06-09-2021

[~sswsharm] did you reproduce it on Oracle JDK by "OS: Mac BigSur version 11.2.3 JDK 11.0.12 :Partial Pass " or OpenJDK? What exactly "Partial Pass" means?
03-09-2021

Issue is reproduced. Keyboard shortcuts are not working. Step 4: The console does not show "hello, menu item" Step 8: The console shows "hello, check box" on JDK 11 but not JDK 16 OS: Mac BigSur version 11.2.3 JDK 15.0.2 :Fail OS: Mac BigSur version 11.2.3 JDK 16 :Fail OS: Mac BigSur version 11.2.3 JDK 11.0.12 :Partial Pass Moving it to dev team for further analysis
03-09-2021