InputMap input=buttonPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
input.put(KeyStroke.getKeyStroke("Ctrl+y"), "yello");
input.put(KeyStroke.getKeyStroke("Ctrl+g"), "green");
input.put(KeyStroke.getKeyStroke("Ctrl+r"), "red");
ActionMap actionMap =buttonPanel.getActionMap();
actionMap.put("yello", yellochane);
actionMap.put("red", redchane);
actionMap.put("green", greenchane);
我想把按钮和键盘对应,使按Ctrl y也能变色的效果但是不知为什么没有反应
input.put(KeyStroke.getKeyStroke("Ctrl+y"), "yello");
input.put(KeyStroke.getKeyStroke("Ctrl+g"), "green");
input.put(KeyStroke.getKeyStroke("Ctrl+r"), "red");
ActionMap actionMap =buttonPanel.getActionMap();
actionMap.put("yello", yellochane);
actionMap.put("red", redchane);
actionMap.put("green", greenchane);
我想把按钮和键盘对应,使按Ctrl y也能变色的效果但是不知为什么没有反应
control G
control R看过KeyStroke的文档的话就不会出这种错误了