Search code examples
javaswingjtextareaword-wrap

Automatic Creation of new text lines in a JTextArea Component


I am using a jTextArea in a javaswing application with Netbeans 7. Want to make it possible to automatically create a new line when the text entered gets to the end of the jtextarea. This will mean that there will not be a horizontal scrollbar. The "enter" button will not need to be pressed before a new line is created

A simple illustration is like when using a word document. A new line is created when the user gets to the end of each line of the document.

Any suggestion.


Solution

  • You can do this using

    textArea.setWrapStyleWord(true);
    textArea.setLineWrap(true);