I am new to GUI programming. While practicing `KeyEvent` handling on Java Swing `JTextarea` I face one problem. The listener interface is implemented by text area itself.

When I pressed `VK_ENTER` key in text area I get text from text area then I displayed that text into `JTextPane`. After that I set text as empty string on text area. Here I used `keyPressed` key event - it is creating one new line in text area but already I set text area row as 0 (zero).

Actually I want one row in text area I don't want two line in text area, How to resolve this problem? 

This is my code:

```
public void keyPressed(KeyEvent evt) {

   try {
       if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
           if (evt.isShiftDown()) {  
              textArea .setText(textArea.getText() + "\n");
           } else {   
                inputMsg = textArea.getText().trim();
                textArea.setText(EMPTYSTRING);
                if (!inputMsg.equals(EMPTYSTRING)) {   
                   textPane.setText(inputMsg);
                }
                textArea.requestFocus();
              }
          }
     } catch (Exception ex) {
         logger.log(Level.SEVERE, "Exception in textArea.keyReleased() : ", ex);
     }
}

```