Nu sidder jeg ikke lige pt ved en maskine med Java på, så jeg kan ikke teste. Men jeg fandt følgende eksempel:
// Define Actions
Action hopAction = new AbstractAction( "Hop" ) {
public void actionPerformed( ActionEvent event ) {
System.out.println( "Hopping" );
}
};
Action skipAction = new AbstractAction( "Skip" ) {
public void actionPerformed( ActionEvent event ) {
System.out.println( "Skipping" );
}
};
// Map action names to actions.
ActionMap aMap = getActionMap();
aMap.put( "Hop", hopAction );
aMap.put( "Skip", skipAction );
// Map keystokes to Actions (via the action names).
InputMap iMap = getInputMap();
iMap.put(
KeyStroke.getKeyStroke( KeyEvent.VK_H, InputEvent.CTRL_MASK ),
"Hop" );
iMap.put(
KeyStroke.getKeyStroke( KeyEvent.VK_S, InputEvent.CTRL_MASK ),
"Skip" );
Kilde:
http://groups.google.dk/groups?hl=da&lr=&threadm=3e185fe1%241%40newsgroups.borland.com&rnum=11&prev=/groups%3Fq%3Djava%2Bshortcut%2Bjbutton%26start%3D10%26hl%3Dda%26lr%3D%26selm%3D3e185fe1%25241%2540newsgroups.borland.com%26rnum%3D11