Search code examples
javajtextarea

appending text in a jTextBox


 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


Solution

  • According to the error message, the jTextArea1 is actually a JTextField.

    Try

    jTextArea1.setText(jTextArea1.getText() + k);