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

Cherie picture Cherie · May 19, 2011 · Viewed 23.9k times · Source

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?)

Answer

EboMike picture EboMike · May 19, 2011

JTextArea.setWrapStyleWord(true)?