javaswingword-wrapjtextarea

JTextArea: how to wrap text by words, not characters?


I want to avoid an output like this:

Here is some text t
hat is being wrappe
d by characters, sp
litting words in ha
lf

I am using a JTextArea, with setLineWrap(true). How can I make it wrap words, though? (Is there a way to make it only wrap when there is a space or something?)


Solution

  • JTextArea.setWrapStyleWord(true)?