JTextPane - dynamic word wrap
Solution 1
Try using a JTextArea
and call setWrapStyleWord(true);
on its instance this should do what you need.
EDIT:
If you need to use a JTextPane
as a requirement(which you said you do), then have a look at a similar question that I found which answer should be of help: How is word-wrapping implemented in JTextPane, and how do I make it wrap a string without spaces?
Solution 2
I had the same problem, the solution from David Kroukamp was very helpful. I changed it to JTextArea and set the following properties, as described in this tutorial:
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
user592704
Updated on June 04, 2022Comments
-
user592704 almost 2 years
I tried to use
jTextPane1.setText("xxx xxxx xxx xxxxx xx xxx xxxx xxx etc...");
butJTextPane
does not word wrap it at all showing all the text in one line only instead. It would be interesting to support word wrap onjTextPane1
resized too...So my question is... how to make
JTextPane
support word wrap? -
user592704 almost 12 yearsbecause I am interested in text pane dynamic rows++ support. Not the scrolling
-
user592704 almost 12 yearsEmm... the issue is about JEditorPane not the JTextPane :( You mean using JEditorPane instead?
-
David Kroukamp almost 12 yearsNo the first link does discuss using JTextPanes, however, yes a JEditor could do that too as seen in the 2nd link of the answer
-
David Kroukamp almost 12 years@user592704, This link too might help: stackoverflow.com/questions/8980792/…
-
searchengine27 over 2 years-1. Why does this have any upvotes? this doesn't answer the question at all. The answer doesn't even say that it is for a
JTextArea
and not aJTextPane
. Not that it matters because, again, the question has nothing to do with aJTextArea
at all.