Search code examples
javaswingjtextareaword-wrap

Propper JTextArea Text Wrappping


I currently use this class to put text into a 'log' JTextArea:

public void appendOutput(String output) { 
    textPane.setText(textPane.getText() + "\n " + output); 
}

This works pretty well except for the fact that a text wrapping JTextArea will cut words in half. Is there a good/easy fix for this?

This is what it does...


Solution

  • JTextArea.setWrapStyleWord(true)
    

    So in your case it would be:

    textPane.setWrapStyleWord(true);