JDK-7151821 : [macosx] Mnemonic doesn't work in JTabbedPane
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,8
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_ubuntu,os_x
  • CPU: generic,x86
  • Submitted: 2012-03-07
  • Updated: 2015-02-26
  • Resolved: 2012-03-23
Related Reports
Duplicate :  
Relates :  
Regression. Last times work in b226.

See regression test javax/swing/JTabbedPane/4624207/bug4624207.java
To reproduce the issue run the code and press Ctrl+Alt+a:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MyKeyTest {

    static JPanel panel;

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                JFrame frame = new JFrame("Test Frame");
                frame.setSize(300, 200);
                panel = new JPanel();
                panel.addKeyListener(new KeyAdapter() {

                    public void keyPressed(KeyEvent e) {
                        System.out.println("[key listener]");
                        System.out.println("key code: " + e.getKeyCode());
                        System.out.println("key char: " + e.getKeyChar());
                        System.out.println("key char int: " + (int) e.getKeyChar());
                frame.getContentPane().add(panel, BorderLayout.CENTER);

        SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {


The result after pressing Ctrl+Alt+a is:
[key listener]
key code: 65
key char: 
key char int: 1
The key char is 1 instead of 'a'

EVALUATION In b226 [event charactersIgnoringModifiers] string from NSEvent was used for keyChar. Now the [event characters] string is used because of the fix: http://java.net/jira/browse/MACOSX_PORT-568 http://hg.openjdk.java.net/jdk7u/jdk7u-osx/jdk/rev/5780795f381e According to the NSEvent doc charactersIgnoringModifiers: This method returns the non-modifier key character pressed for dead keys, such as Option-e. For example, Option-e (no shift key) returns an ���e" for this method, whereas the characters method returns an empty string.

EVALUATION EventQueue receives a KeyEvent with the key code 66 and key char 2 ((int) e.getKeyChar()) for the B mnemonic. The key char is incorrect in this case.