简体   繁体   中英

To append into jtextarea from another jtextarea using jbutton

I have developed a swing GUI in which I try to populate a text area with the text from another text area using button.

Code:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {     

jTextArea2.setText(4.0+" "+jTextArea1.getText().trim());
jTextArea1.setText("")
}

It is working fine if I enter the text first time in TextArea1 and hit the button to populate the TextArea2. But if I enter a new text in TextArea1 and hit the button instead of appending it to the TextArea2 it replaces the text.

Please suggest me how to correct the same.

您不应调用append setText

jTextArea2.append(4.0+" "+jTextArea1.getText().trim());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM