How to get a JTextField to respond to the enter key
问题 So I want to get a JTexField to put the text in it into a JTextArea when the enter key is pressed with the cursor in it. Can anyone help? 回答1: Forget about using KeyListener for Swing components. This listener was designed for use with AWT components does not provide a reliable interaction mechanism for JTextComponents . Use an ActionListener instead - on the vast majority of systems an ActionEvent is dispatched by the JTextField when enter is pressed. myTextField.addActionListener(new