2012-12-20 1 views

답변

6

키 바인딩에 대한 개요는 Java Tutorial을 참조하십시오.

import java.awt.event.*; 
import javax.swing.*; 

public class KeyBindings extends Box{ 
    public KeyBindings(){ 
     super(BoxLayout.Y_AXIS); 
     final JTextPane textArea = new JTextPane(); 
     textArea.insertComponent(new JLabel("Text")); 
     add(textArea); 

     Action action = new AbstractAction() { 
      @Override 
      public void actionPerformed(ActionEvent e) { 
       textArea.setText("New Text"); 
      }}; 
     String keyStrokeAndKey = "control SPACE"; 
     KeyStroke keyStroke = KeyStroke.getKeyStroke(keyStrokeAndKey); 
     textArea.getInputMap().put(keyStroke, keyStrokeAndKey); 
     textArea.getActionMap().put(keyStrokeAndKey, action); 
    } 


    public static void main(String[] args) { 
     JFrame frame = new JFrame(); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.setContentPane(new KeyBindings()); 
     frame.pack(); 
     frame.setVisible(true); 
    } 
} 
+0

무엇을 생각! 그것은 일을했다. 조언 주셔서 감사합니다 및 솔루션을 주셔서 감사합니다 그것은 JTextField에 대해 동일 하 고 나는 keyBindings를 조회합니다. – Azad

관련 문제