1.定义一个监听类:
class SetCurrentUserListener extends AbstractAction {
public void actionPerformed(ActionEvent arg0) {
setCurrentUser();
}
}
2. 定义一个常量字符串,用于在后面把Action和键盘的code建立关联
private static String key_setUser = "setUser";
3. 获取键盘VK 并put到kdtable的InputMap中
KeyStroke ctrl_f7 = KeyStroke.getKeyStroke(KeyEvent.VK_SHIFT,KeyEvent.VK_F7 2);
tblMain.getInputMap(1).put(ctrl_f7, key_setUser);
4.将action放入到kdtable的ActionMap中
ActionMap actionMap = tblMain.getActionMap();
actionMap.put(key_setUser, listenerUser);