help on JtextArea

hi,how to make textarea as empty , i used setText("");it is clearing text area , but it contains the empty line.how can i make textarea as empty textarea .please help me.
[237 byte] By [kiran@grdemettlea] at [2007-11-26 21:00:52]
# 1

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.

camickra at 2007-7-10 2:31:59 > top of Java-index,Desktop,Core GUI APIs...
# 2
Doesn't it sound same ?Maybe you can tell more, what you expect
Thunder_Blasta at 2007-7-10 2:31:59 > top of Java-index,Desktop,Core GUI APIs...
# 3

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

kiran@grdemettlea at 2007-7-10 2:31:59 > top of Java-index,Desktop,Core GUI APIs...
# 4
Are you sure? because if only based the small part of the code that you gave, it should back to the 1st position of the JTextArea. Unless you have set it with "\n" (which means new line) later on.
Thunder_Blasta at 2007-7-10 2:31:59 > top of Java-index,Desktop,Core GUI APIs...
# 5
i haven't used "\n " in my program but the cursor is moving to next line when i pressed enter key
kiran@grdemettlea at 2007-7-10 2:31:59 > top of Java-index,Desktop,Core GUI APIs...
# 6
> i haven't used "\n " in my program > but the cursor is moving to next line when i pressed> enter keyDoesn't it should be like that ?
Thunder_Blasta at 2007-7-10 2:31:59 > top of Java-index,Desktop,Core GUI APIs...
# 7

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();

}

});

}

}

weebiba at 2007-7-10 2:31:59 > top of Java-index,Desktop,Core GUI APIs...
# 8
thank you very much , i have solved the problem
kiran@grdemettlea at 2007-7-10 2:31:59 > top of Java-index,Desktop,Core GUI APIs...