I have a JTextArea object - chat log. I'm using setText (); I send messages sent by users to the chat log. The text variable is responsible for the entire text of the log, respectively, all messages are displayed not on a new line but in one line. Tell me how to fix.

    2 answers 2

    at the end of each addition of text, add '\ n' to the end of the line. And it is better to add text using the append () method instead of setText ().

    • one
      I will add that for Windows \ r \ n, for unix \ n, for mac \ r - Aleksei Chibisov

    Add a newline character between messages.

    For example:

    String text = "1" + "\n" + "2"; 

    or so:

     String text = "1" + System.lineSeparator() + "2"; 

    As a result, one and two will be on different lines.