title: Java Swing How to reset JTextArea
body: <p>I am making a program where the user can type a string message into a JTextArea component, and press enter so that the message is sent, and then the JTextArea should be cleared and the caret position reset to 0.</p>
  
  <pre><code>    JTextArea userChatBox = new JTextArea();
      userChatBox.addKeyListener(new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
              if (e.getKeyCode()==10){
              //If key pressed is enter.  
                  client.send(userChatBox.getText());
                  userChatBox.setCaretPosition(0);
                  userChatBox.setText("");
  
              }
  
          }
      });
      userChatBox.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, null, null, null, null));
      userChatBox.setTabSize(4);
      userChatBox.setLineWrap(true);
      userChatBox.setForeground(UIManager.getColor("ColorChooser.foreground"));
      userChatBox.setFont(new Font("DejaVu Serif", Font.PLAIN, 12));
      userChatBox.setBackground(Color.WHITE);
      userChatBox.setBounds(10, 255, 400, 80);
      frmChatClient.getContentPane().add(userChatBox);
  </code></pre>
  
  <p>However, when the user presses enter, the JTextArea registers this as a return and enters a new line. Even after <code>userChatBox.setCaretPosition(0);</code>, the caret appears on the second line, and subsequently any string sent from the JTextArea will include a blank line. I have also tried setting the selection start and end with no avail.</p>