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 :  
Description
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);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                panel = new JPanel();
                panel.addKeyListener(new KeyAdapter() {

                    @Override
                    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);
                panel.requestFocus();
                frame.setVisible(true);
            }
        });

        SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                panel.requestFocus();
            }
        });
    }

}
------------------------------

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'

Comments
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.
13-03-2012

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.
11-03-2012