What do you mean it has an "empty line"?
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.
i have two textarea's in my frame ,
1. txtTyingArea(here user can type anything)
whenever user presses the enter key i am clearing txtTyingArea.
it is clearing , but the cursor moves to the second line of the textArea.
but i want cursor in starting position of the textarea
This slightly hackish program is what Camickr meant by "Short, Self Contained, Compilable and Executable, Example Program". I suspect that you forgot to consume the event.import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
public class TestTextArea {
private static void test() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JTextArea ta = new JTextArea(5, 10);
ta.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
e.consume();
ta.setText("");
}
}
});
f.setContentPane(new JScrollPane(ta));
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
test();
}
});
}
}