How to use TextListener

Hy to all!I have a probleme!I have a JPanel with 2 TextArea!How can i do that if i'm writing in one of the textAreas,at the same time, the text appears in the other one!Pleas help!

[188 byte] By [killer8685a] at [2007-11-27 10:25:11]
# 1

Use a CaretListener. Somethin similar to the code below should give you some results.

JTextArea txt1 = new JTextArea();

JTextArea txt2 = new JTextArea();

txt1.addCaretListener( new CaretListener() {

public void caretUpdate(CaretEvent e) {

txt2.setText( txt1.getText() );

}

});

ICE

icewalker2ga at 2007-7-28 17:32:13 > top of Java-index,Desktop,Core GUI APIs...
# 2

Share the model:

JTextArea textArea1 = new JTextArea();

JTextArea textArea2 = new JTextArea(textArea1.getDocument());

camickra at 2007-7-28 17:32:13 > top of Java-index,Desktop,Core GUI APIs...
# 3

Thanks!It really worked!

But the problem is that i must use textListener!Can u give me an idea how to use it?

Thanks!

killer8685a at 2007-7-28 17:32:13 > top of Java-index,Desktop,Core GUI APIs...
# 4

> But the problem is that i must use textListener

Then you are in the wrong forum. A TextListener is only for TextField and TextArea which are AWT components. You don't use AWT components in a Swing application.

This is a Swing forum and you should be using JTextField or JTextArea and then you use the approach I gave above or use a DocumentListener.

camickra at 2007-7-28 17:32:13 > top of Java-index,Desktop,Core GUI APIs...