我有下面的屏幕:
public BillSummaryScreen() {
..........
ShortcutKeyUtils.createShortcutKey(this, KeyEvent.VK_ENTER, "enterShortcut", new EnterAction());
}
public static void createShortcutKey(JComponent panel, int keyEventCode, String actionShortcutName, AbstractAction action){
InputMap inputMap = panel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(KeyStroke.getKeyStroke(keyEventCode, 0), actionShortcutName);
ActionMap actionMap = panel.getActionMap();
actionMap.put(actionShortcutName, action);
}
private class EnterAction extends AbstractAction{
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("EnterAction");
}
}
我想按“ENTER”键,以便单击搜索按钮。但是当我专注于一个组合框(通过鼠标)并按下 ENTER 时,该操作不起作用