title: JavaFX: How to make enter key submit TextArea
body: <p>Sorry if this seems a little too easy, I'm brand new to JavaFX, this is my first little app built with it.</p>
  
  <p>I am trying to make a bare bones chat client. I am using the JavaFX Scene builder to make the client UI, and a controller class connected to the FXML.</p>
  
  <p>How can I make is so that the current text of in the text area is submitted to the server and the text area is cleared upon the enter key press, instead of using some kind of "send" button?</p>
  
  <p>EDIT: Here is the code that is not working:</p>
  
  <pre><code>//...
  
  public class FXMLDocumentController
  {
  
  //...
  
  @FXML private TextArea messageBox;
  
  //...
  
  messageBox.setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;() 
  {
      @Override
      public void handle(KeyEvent keyEvent) 
      {
          if(keyEvent.getCode() == KeyCode.ENTER)
          {
              //sendMessage();
          }
      }
  });
  
  //...
  </code></pre>