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!
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!
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
Share the model:
JTextArea textArea1 = new JTextArea();
JTextArea textArea2 = new JTextArea(textArea1.getDocument());
Thanks!It really worked!
But the problem is that i must use textListener!Can u give me an idea how to use it?
Thanks!
> 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.