Reputation: 9416
public void actionPerformed(ActionEvent evt) {// handle button event
Object source = evt.getSource();
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
Upvotes: 1
Views: 5131
Reputation: 420921
According to the error message, the jTextArea1
is actually a JTextField
.
Try
jTextArea1.setText(jTextArea1.getText() + k);
Upvotes: 2
Reputation: 23206
you could also use :
String x = jTextArea.getText();
String a = x + k ; // String k = evt.getActionCommand();
jTextArea.setText(a);
Upvotes: 0
Reputation: 2708
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")
.
Upvotes: 1