0

I have to use one of Windows L&F for my Java application on OSX. Unfortunately, I can't change L&F to any Apple compatible.

It's very inconvenient to use windows hot keys (ctrl+c instead of cmd+c etc). Possible exists a "hack" that allows me globally to use command key instead of control (cmd -> ctrl) in hotkeys of windows L&F (don't wish to override key binding for each control)?

I use JGoodies Looks if it's matter.

FoxyBOA
  • 5,788
  • 8
  • 48
  • 82

1 Answers1

1

Found what I've looked for:

if (Desktop.getDesktop().isMacOSX()){
    // see MetalLookAndFeel class for details
    String[] keys = {"TextField.focusInputMap", "PasswordField.focusInputMap", "TextArea.focusInputMap", "TextPane.focusInputMap", "EditorPane.focusInputMap", "FormattedTextField.focusInputMap"};
    //              , "List.focusInputMap", "Table.ancestorInputMap", "Tree.focusInputMap"};
    for(String item : keys){
        InputMapUIResource map = (InputMapUIResource) UIManager.get(item);
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.META_MASK), DefaultEditorKit.copyAction);
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.META_MASK), DefaultEditorKit.pasteAction);
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.META_MASK), DefaultEditorKit.selectAllAction);
        map.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.META_MASK), DefaultEditorKit.cutAction);
    }
FoxyBOA
  • 5,788
  • 8
  • 48
  • 82
  • This works on Mac OS X, but not on Windows; use `getMenuShortcutKeyMask()`, for [example](http://stackoverflow.com/a/8105344/230513), instead. – trashgod Sep 06 '15 at 02:39
  • @trashgod: I can't get your hint. I've working Windows L&F that's doing everything perfect on Windows. I need to "adjust" it somehow for OS X to use at least native OS X copy/cut/paste actions. That what I did in the code. I can use `getMenuShortcutKeyMask()` instead of `KeyEvent.META_MASK` but this change anything. Please, explain your point. – FoxyBOA Sep 06 '15 at 06:02