Skip to content

Implement possibility to wrap long words on html page loaded into JEditorPane

License

Notifications You must be signed in to change notification settings

asilichenko/swing-html-paragraph-wrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java swing html paragraph wrap

Screenshot of default state Screenshot of a result

By default there are some issues with long text displaying in html page loaded into JEditorPane.

  1. content of the pre-blocks is not wrapped at all;
  2. long like super long word or symbol seqence is not wrapped anywhere.

One extra issue: how to wrap a text in JEditorPane inside JScrollPane if we don't need to use horizontal scroll bar?

Let's start from the ending:

  • just override method JEditorPane.getScrollableTracksViewportWidth and put "return true;" inside.

For the first two issues we need to override classes javax.swing.text.html.HTMLEditorKit and javax.swing.text.html.ParagraphView.

Our HTMLEditorKit should just return an object of our ParagraphView for specific tags.

Custom ParagraphView should return 0 in the method getMinimumSpan for X-axis.

BTW, HTMLEditorKit implements HTML spec ver. 3.2. The specification is from as early as 1997:

https://www.w3.org/TR/2018/SPSD-html32-20180315/