2

In Java Swing, the JTextPane has word wrap when the text exceeds width, but it does NOT line break for when there's a very long non-space string.

How can I make a JTextPane line break for a long non-space string?

Any ideas would be much appreciated, thanks.

Jasperan
  • 2,154
  • 1
  • 16
  • 40
didxga
  • 5,935
  • 4
  • 43
  • 58
  • http://java-sl.com/tip_letter_wrap_java7.html you have to define min width for label view = 0 – StanislavL May 27 '14 at 07:43
  • Also this http://java-sl.com/tip_java7_text_wrapping_bug_fix.html could help – StanislavL May 27 '14 at 07:43
  • @StanislavL, Thanks, I tried solution of your first link. I get java.lang.ClassCastException: javax.swing.text.DefaultStyledDocument cannot be cast to javax.swing.text.html.HTMLDocument at javax.swing.text.html.ParagraphView.getStyleSheet(ParagraphView.java:132) – didxga May 27 '14 at 07:52
  • My example has no relation to HTMLDocument at all. Don't know whta's wrong with **your code** – StanislavL May 27 '14 at 07:55
  • ok, I will investigate on this, maybe my code did something messy – didxga May 27 '14 at 07:56
  • @StanislavL, It turned out that I imported wrong ParagraphView. Your solution works like a charm, please considering put your comments as an answer for other people's reference. Thanks! – didxga May 28 '14 at 03:02

1 Answers1

3

To allow letter wrap LabelView should be modified to override min width

java-sl.com/tip_letter_wrap_java7.html you have to define min width for label view = 0

Also this java-sl.com/tip_java7_text_wrapping_bug_fix.html could help

Posted as an answer from my comment.

Jasperan
  • 2,154
  • 1
  • 16
  • 40
StanislavL
  • 56,971
  • 9
  • 68
  • 98