JDK-8194873 : right ALT key hotkeys no longer work in Swing components
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 9,10
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • CPU: x86
  • Submitted: 2018-01-06
  • Updated: 2022-07-11
  • Resolved: 2018-06-25
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 11 JDK 12 JDK 8 Other
11 b20Fixed 12Fixed 8u311Fixed openjdk8u352Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
9.0.1

ADDITIONAL OS VERSION INFORMATION :
Win10 x64

EXTRA RELEVANT SYSTEM CONFIGURATION :
Java 9.0.1

A DESCRIPTION OF THE PROBLEM :
The right ALT key has extra bits set when calling KeyEvent.getModifiers() which causes ALT + ? hotkeys to fail.
Even Swing dialogs like JOptionPane.showMessageDialog() don't work (ALT+N ALT+Y don't work).
Only the right ALT is affected.

REGRESSION.  Last worked in version 8u152

ADDITIONAL REGRESSION INFORMATION: 
1.8_152

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Upgrade to 9 or 9.0.1 and right ALT no longer works as expected.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Right ALT works.
ACTUAL -
Right ALT returns ALT_MASK and ALT_GRAPH_MASK bits.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
JOptionPane.showConfirmDialog(this, "Do you wish to save file?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION)
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Downgrade to 8.0


Comments
RightAltKeyTest.java (included by JDK-8194873) fails without JDK-8155742
02-06-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk8u-dev/pull/60 Date: 2022-05-17 18:31:23 +0000
19-05-2022

Fix request (8u) - will label after testing completed This issue is observed on jdk8u as well. The patch applied manually for 2 files (MotifLookAndFeel.java, SwingUtilities2.java) because of the context differences.
17-05-2022

8u has dependency on JDK-8155742 backport
14-10-2021

This bug is caused by the fix for the bug JDK-8041928. Today I have verified this by means of the attached test case and by using a custom build of JDK 8 compiled from the latest version of its development source code to which I applied the fix JDK-8041928. The bug is reproducible on such a custom build of JDK 8 with the fix JDK-8041928 and is not reproducible on a build of JDK 8 without the fix. Adding the label "regression_8041928".
23-07-2021

URL: http://hg.openjdk.java.net/jdk/jdk/rev/86897f8a6598 User: prr Date: 2018-06-27 17:56:36 +0000
27-06-2018

URL: http://hg.openjdk.java.net/jdk/client/rev/86897f8a6598 User: pbansal Date: 2018-06-25 08:22:19 +0000
25-06-2018

Retargeted to 12, please continue working on it and bring it back to 11 if it is ready by Jun 26
21-06-2018

A new review request has been sent for this webrev: http://cr.openjdk.java.net/~pbansal/8194873/webrev.03/
20-06-2018

This issue was introduced when a check for VK_RMENU was added in GetJavaModifiers function in awt_Component.cpp. Windows gives true for both VK_MENU and VK_RMENU when right ALT (ALT_GRAPH ) key is pressed. Due to which extra bits are set on modifiers. So the mnemonic bindings should be updated to work with both ALT and (ALT+ALT_GRAPH) modifiers. Changes have been made for JOptions_Pane, JMenu, JTabbedPane and JTextField and they work fine after changes mentioned in webrev. Only thing remaining is how to make the JMenuItem work with ALT_GRAPH key. There are two ways to set the mnemonic bindings in JMenuItems and problem is with second case 1. JMenuItem newMenuItem = new JMenuItem("New"); newMenuItem.setMnemonic(KeyEvent.VK_N); In this case, the event is triggered if the N key is pressed. The modifiers are not used in this and pressing only N will work. So ALT or ALT_GRAPH is not required. These shortcut only work if the menu containing the given menu item is expanded. 2. JMenuItem newMenuItem = new JMenuItem("New"); newMenuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_N, InputEvent.ALT_MASK)); In this case we are setting the accelerator key. In this case the key N will work with the modifier passed here. I am trying to make the JMenuItem work with ALT_GRAPH_MASK. Note: There is no ActionEvent.ALT_GRAPH_MASK. Do we need to add that too? webrev: http://cr.openjdk.java.net/~pbansal/8194873/webrev.02/
20-06-2018

Adding workaround as shared by the submitter: ===================== public static void removeAltGraph() { KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { public boolean dispatchKeyEvent(KeyEvent e) { int mods = e.getModifiers(); if ((mods & KeyEvent.ALT_GRAPH_MASK) != 0) { mods &= ~KeyEvent.ALT_GRAPH_MASK; e.setModifiers(mods); } return false; } }); } =============================== I've learned more about this bug. The AltGraph key and the right Alt Key use the same scancode which you can read about in https://en.wikipedia.org/wiki/AltGr_key Don't think there will be an easy fix to this. Created a netbeans plugin to remove the AltGraph code from KeyEvent's for now available on https://github.com/pquiring/RemoveAltGraph
06-04-2018

http://mail.openjdk.java.net/pipermail/swing-dev/2018-March/008433.html
09-03-2018

This is reproducible on Windows 10 with jdk 10, jdk9_181. It passes on jdk8_152u.
11-01-2018

Reported With: JDK 9.0.1 Windows 10 Right ALT key (hotkey) does not work in Swing components. Verified this with respective JDK version and could confirm the issue. Results: ======== 8: OK 8u152: OK 9: FAIL 9.0.1: FAIL 10 ea b38: FAIL To verify, run the attached test case with respective JDK version. Note that Left (ALT+Y) works fine whereas Right (ALT+Y) Fails to work. This seems a regression in JDK 9 and above.
10-01-2018