The word wrapping method provided for JTextArea is not working in my program. Why isn’t it working? How can I fix it? Here is the code:
text= new JTextArea(15,65);
text.setWrapStyleWord(true); // word wrapping enabled
text.setPreferredSize(new Dimension(getPreferredSize()));
Here is the screenshot. The last word goes out of frame.

The following SSCCE let you experiment with both settings. Here you can see that using
setWrapStyleWordhas no effect if you do not callsetLineWrapfirst. This is also documented in the javadoc ofsetWrapStyleWord.The best results for a readable form is setting them both to true.