Tag: 密钥绑定

Java Keybindings

我需要绑定所有箭头键来执行相同的function,但每次都按下哪个键。 目前我只有在通过以下方式按下右箭头键时才有 DoneImg.getInputMap(JLabel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), “UpArrow”); Action MvRight = new AbstractAction() { public void actionPerformed(ActionEvent e) { //Do whatever here } }; DoneImg.getActionMap().put(“RightArrow”, MvRight); 但我需要类似的东西 DoneImg.getInputMap(JLabel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), “RightArrow”); DoneImg.getInputMap(JLabel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), “LeftArrow”); DoneImg.getInputMap(JLabel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), “DownArrow”); DoneImg.getInputMap(JLabel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), “UpArrow”); Action MvAll = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (e.keypressed == “LeftArrow”) {System.out.println(“The left arrow was […]