JTextField does not interpret \ n as line break

-1

When printing client data in the JTextField, when \n is present it means a line break, but instead of moving to the next line each time it finds a \n , it simply ignores and continues to write forward.

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 look 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?

    
asked by anonymous 25.11.2015 / 18:47

1 answer

1

Not updating correctly, put two bars instead of one.

Replace with:

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());
    
25.11.2015 / 19:26