![](/img/trans.png)
[英]How to make a JButton add text from one JTextArea to another JTextArea
[英]To append into jtextarea from another jtextarea using jbutton
我開發了一個swing GUI,在其中嘗試用按鈕使用來自另一個文本區域的文本填充文本區域。
碼:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea2.setText(4.0+" "+jTextArea1.getText().trim());
jTextArea1.setText("")
}
如果我第一次在TextArea1中輸入文本,然后單擊按鈕以填充TextArea2,則效果很好。 但是,如果我在TextArea1中輸入新文本並按下按鈕,而不是將其附加到TextArea2,它將替換該文本。
請建議我如何更正。
您不應調用append
setText
jTextArea2.append(4.0+" "+jTextArea1.getText().trim());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.