Mac Keyboard Shortcuts with Nimbus LAF

后端 未结 2 1579
小蘑菇
小蘑菇 2020-12-21 01:27

Is there a way to use Nimbus LAF (Look And Feel) on OS X while still being able to use the Meta key for cut/copy/paste and select-all operations?

I curren

2条回答
  •  时光说笑
    2020-12-21 01:55

    Using the getMenuShortcutKeyMask() method works with NimbusLookAndFeel to enable the key, as shown in this example. See also this related answer.

    In the particular case of a JTextField, you can use the mask in a key binding that evokes the original action.

    int MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    JTextField jtf = new JTextField("Test");
    jtf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, MASK), "select-all");
    jtf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, MASK), "copy");
    jtf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_X, MASK), "cut");
    jtf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, MASK), "paste");
    

提交回复
热议问题