开发者

appending text in a jTextBox

开发者 https://www.devze.com 2023-03-15 16:02 出处:网络
public void actionPerformed(ActionEvent evt) {// handle button event Object source = evt.getSource();
 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);  
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号