Search code examples
javaswingjtextarea

How can I split the data over multiple lines in a JTextArea?


How can I put each line of the host in the message body? I work with a JTextArea.

String host = InetAddress.getLocalHost().getHostName().toString();
texto_recepcion.setText(host + texto_recepcion.getText() + dpRecepcion.getAddress() + " " + mensaje_recibido + "\n");

How it is now:

enter image description here


Solution

  • I resolve my question with append function.

    String host = InetAddress.getLocalHost().getHostName().toString();
    
    texto_recepcion.append(host); // ***Use the function append for solve the problem***
    
    texto_recepcion.setText(texto_recepcion.getText() + dpRecepcion.getAddress() + " " + mensaje_recibido + "\n");
    

    Thanks a lot