-
Bug
-
Resolution: Unresolved
-
P3
-
8, 9, 11, 15, 16, 17
-
x86_64
-
os_x
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
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
- blocks
-
CODETOOLS-7903087 Fix native MacOS menu support
- New
- relates to
-
JDK-8152492 [macosx swing] double key event actions when using Mac menubar
- Resolved
-
JDK-8216971 [macosx swing] For JCheckBoxMenuItem actionPerformed() is called twice, when apple.laf.useScreenMenuBar=true and modifier is InputEvent.META_DOWN_MASK
- Resolved