This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

JTextPane ignores new line HTML <br> tag when using custom HTMLEditorKit  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

In my application I use a JTextPane embedded in a JScrollPane to display text which is formatted using HTML tags. At first I used JTextArea but then switched to JTextPane to be able to use HTML and colors. Then I needed the JTextPane to support letter based wrapping instead of just the default wrapping by white space. In other words if the content is too long it should be wrapped and the horizontal scroll bar of the JScrollPane should not be visible.

Therefore, I found a solution in this answer that works perfectly:  Letter wrap in html in JEditorPane. It uses a custom HTMLEditorKit for the JTextPane.

But with this solution the JTextPane ignores any line breaks with the HTML tag <br>. I have to admit I don't really know how the code in the solution works. It would be great if someone could find out how to get the HTML new line <br> tag working with this solution.

TL;DR: how to get this custom HTMLEditorKit to support the HTML "<br>" tag?

Here is a minimal, complete & verifiable example:



 
Marshal
Posts: 61739
193
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm is right; please tell the people on dreamincode too that you have posted on several websites.
 
John Sams
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for posting on multiples sites, I didn't thought I get the solution this quick!

In fact, a german forum posting solved my problem. Here's the code:



thnaks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!