Jtextfield does not interpret n as line breaking

Asked

Viewed 1,961 times

-1

When printing customer data in Jtextfield, when the \n is present means a line break, but instead of moving to the next line each time you find a \n, he simply ignores and continues to write in front.

Follow the code below:

lista.setText(clientes[i].toString());

public String toString(){
    return String.format("\t-----------------------Cliente Regular-------------------------\n[%s]\t-> Nome: %s\n\t->Contacto: %s\n\t->NIF: %d\n\t->E-email: %s\n\t->Morada: %s\n",super.getnickname(),super.getnome(),super.getcontacto(),super.getnif(),super.getemail(),super.getmorada());
}

And your output should be something like:

"\t-----------------------Cliente Regular-------------------------\n
[%s]\t-> Nome: %s\n
\t->Contacto: %s\n
\t->NIF: %d\n
\t->E-email: %s\n
\t->Morada: %s\n"

Can someone help me?

  • If the string text is written manually, it is no longer easy to delete the n?

  • the image couldn’t see João, only the one logged in will be able to see. Stack Overflow has its own image Uploader above the editor.

1 answer

1

Not updating correctly, put two bars instead of one.

Substitute for:

return String.format("\t-----------------------Cliente Regular-------------------------\n[%s]\t-> Nome: %s\n\t->Contacto: %s\n\t->NIF: %d\n\t->E-email: %s\n\t->Morada: %s\n",super.getnickname(),super.getnome(),super.getcontacto(),super.getnif(),super.getemail(),super.getmorada());

To:

return String.format("\\t-----------------------Cliente Regular-------------------------\\n[%s]\t-> Nome: %s\\n\\t->Contacto: %s\\n\\t->NIF: %d\\n\\t->E-email: %s\\n\\t->Morada: %s\\n",super.getnickname(),super.getnome(),super.getcontacto(),super.getnif(),super.getemail(),super.getmorada());

Browser other questions tagged

You are not signed in. Login or sign up in order to post.