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

11
LINES

< > BotCompany Repo | #1004136 // registerKey - Note: always registers a key for a whole JFrame!

JavaX fragment (include)

1  
// keyCode = KeyEvent VK_...
2  
static void registerKey(JComponent c, int keyCode, S name, final O r) {
3  
  Action action = abstractAction(name, r);
4  
  KeyStroke keyStroke = KeyStroke.getKeyStroke(keyCode, 0);
5  
  c.getActionMap().put(name, action);
6  
  c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, name);
7  
}
8  
9  
static void registerKey(JFrame frame, int keyCode, S name, final O r) {
10  
  registerKey(frame.getRootPane(), keyCode, name, r);
11  
}

Author comment

Began life as a copy of #1003691

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004136
Snippet name: registerKey - Note: always registers a key for a whole JFrame!
Eternal ID of this version: #1004136/1
Text MD5: 071d90845964e016d01e4336d9da2c11
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-01-31 06:44:22
Source code size: 457 bytes / 11 lines
Pitched / IR pitched: No / No
Views / Downloads: 649 / 614
Referenced in: [show references]