No of visitors who read this post: 261
Category: Java
Type: Question
No votes yet

Hello friends,

I am writing a program in java. The screenshot of the program is as follows:

The method append (string) is undefined for the JTextFeild

The method append (string) is undefined for the JTextFeild

As you can see above I get a red line under "append". Why is that so? I have observed that I always get it, when I use a jtext field. When I use the jtext area instead of the field, it is resolved.

Why is this so? Can anyone please guide me how to get rid of this error?

Waiting for your replies.

Kindest regards.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

#

Dear User,

You should read the API (Application Programming Interface). By looking at the API you can see if there is such a method there for that class. If it doesn’t have, then you simply can’t use it .

Thank you

# (Solution Accepted)

Hi Warren,

That error occurs because you cannot use that method using a jtextfield since it can only support single line of text. So basically it will only work in the jtextarea instead.

I would suggest, you read the API or the Application Programming Interface so that it will help you develop, learn and understand a program easily.

#

Hi Warren Donaldson,

Always try to avoid appending your characters in “StringBuffer.append”. As you’ve mentioned in problem, this will put a red line under "append". Instead of that you can use the following code “strBuffer.append('a'); //. This is the same process in jTextfieldImg.append. Use ‘\n’ instead of “\n”. Hope this solves your issue.