Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 567
Cherie Avatar asked May 19 '11 01:05

Cherie


People also ask

How do you wrap text in a Jframe?

To wrap the lines of JTextArea we need to call the setLineWrap(boolean wrap) method and pass a true boolean value as the parameter. The setWrapStyleWord(boolean word) method wrap the lines at word boundaries when we set it to true .

What happens if you press Enter in a JTextArea?

If focus is on a JTextField and enter is pressed, the text field fires an ActionEvent.


1 Answers

JTextArea.setWrapStyleWord(true)?

like image 128
EboMike Avatar answered Sep 28 '22 04:09

EboMike