Everywhere I read answers of people finding ways of enabling word wrapping in a JTextPane
, but none of them work for me. I'm using an HTMLDocument
(to display "text/html"
content) and nothing that I have found so far got it to work. The JTextPane
always cause the JScrollPane to scroll horizontally. I need the JTextPane to be scrollable, but only vertically.
Would anyone have a workable demo of a word wrapping JTextPane
displaying HTML content?
There are several duplicates of this question, and many answers, but none that I have found have a single-component solution to the problem. This class is based on one of Stanislav's solutions to a similar problem with plain-text wrapping, with a few changes. This solution is tested with Java 1.7.0_55.
Use this as example to implement custom wrap (whatever you need) http://java-sl.com/tip_html_letter_wrap.html
http://java-sl.com/wrap.html