appending text in a jTextBox
public void actionPerformed(ActionEvent evt) {// handle button event
Object source = evt.getSource();
开发者_如何学JAVA String k = evt.getActionCommand();
jTextArea1.append(k);
}
i have the code above and an error at jTextArea1.append(k);
. The error am getting is
cannot find symbol symbol: method append(java.lang.String) location: variable txtArea of type javax.swing.JTextField
if i use jTextArea1.settext(k); , it works but i want to append text the existing
According to the error message, the jTextArea1
is actually a JTextField
.
Try
jTextArea1.setText(jTextArea1.getText() + k);
Seem like the type of jTextArea1
is JTextField
. Declare jTextArea1 as
JTextArea jTextArea1 = new JTextArea();
Then you will be able to use the method append("string")
.
you could also use :
String x = jTextArea.getText();
String a = x + k ; // String k = evt.getActionCommand();
jTextArea.setText(a);
精彩评论