JDK-8007212 : [macosx] Command key symbol not shown in key modifier text
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2013-01-30
  • Updated: 2013-08-13
  • Resolved: 2013-08-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 8
8Resolved
Related Reports
Cloners :  
Cloners :  
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)

ADDITIONAL OS VERSION INFORMATION :
Mac OS X Lion (10.7.4)

A DESCRIPTION OF THE PROBLEM :
In Java 7 on Mac the Command key symbol is not return from the method KeyEvent#getKeyModifiersText. Instead the text "Meta" is returned.

REGRESSION.  Regression from Apple's Java 6uX

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached snippet. Move the mouse cursor over the button and notice the tooltip.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The tooltip should be the Command key symbol + F.
ACTUAL -
The tooltip is "Meta + F".

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Toolkit;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.KeyStroke;

public class KeyModifierDemo extends JPanel {

  public KeyModifierDemo() {
    final JButton b1 = new JButton("Button with tooltip");
    final KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F,  Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    b1.setToolTipText(getToolTipText(keyStroke));
    add(b1);
  }

  public static String getToolTipText(final KeyStroke keyStroke) {
    final String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode());
    final String modifier = KeyEvent.getKeyModifiersText(keyStroke.getModifiers());
    return (keyStroke.getModifiers() != 0) ? modifier + "+" + keyText : keyText;
  }

  private static void createAndShowGUI() {
    final JFrame frame = new JFrame("Key modifier demo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final KeyModifierDemo newContentPane = new KeyModifierDemo();
    frame.setContentPane(newContentPane);
    frame.pack();
    frame.setVisible(true);
  }

  public static void main(final String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        createAndShowGUI();
      }
    });
  }
}
---------- END SOURCE ----------