Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

21
LINES

< > BotCompany Repo | #1003690 // Test Window-Wide KeyListener on F1

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1414L/10K/34K).

!752

p-awt {
  Action action = new AbstractAction("Do It") {
    public void actionPerformed(ActionEvent evt) {
      print("Yo!");
    }
  };
  
  // This is the component we will register the keyboard shortcut with.
  JFrame frame = showFrame();
  JComponent pnl = frame.getRootPane();
  
  // F1
  KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0);
  
  // Register Action in component's ActionMap.
  pnl.getActionMap().put("Do It", action);
  
  pnl.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "Do It");
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1252 stefan Works! 2016-07-25 21:22:47

add comment

Snippet ID: #1003690
Snippet name: Test Window-Wide KeyListener on F1
Eternal ID of this version: #1003690/1
Text MD5: 11e1778353ab82961624aec907610e39
Transpilation MD5: d4d698453b6ee2f406be288ce1040a37
Author: stefan
Category: javax / gui
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-07-25 21:22:05
Source code size: 562 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 879 / 952
Referenced in: #1003691 - registerFunctionKey - register function key (F1...F12) for a whole JFrame