Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Word wraping behaviour in JTextPane since Java 7

908455Apr 11 2012 — edited Dec 20 2012
Hi,
I have the following problem. I've always used a JTextPane in a small editor application. Until Java version 1.6.x the wrapping of long lines worked without any problems automatically (long lines have been wrapped if possible between words, if not possible (e.g. with very long words) inside the word at the right border of the JTextPane).

Since Java 7 the wrap behaviour has changed. If you now have a long line a horizontal scrollbar appears, no wrapping is done anymore. It seems the EditorKit has somehow changed - but I found no documentation.

First step I've tried:
overridden JTextPane and added the following method

@Override
public boolean getScrollableTracksViewportWidth() {
return true;
}

But this helps only 50% :-( long lines are now wrapped correctly if you have space between the words, but if you have a really long word a strange behaviour occurs: sometimes wrapping is done but mostly not. I have no idea.

I've already found a bug-report at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7125737 but the report was closed as "not a bug".

I'm using the default EditorKit - has anyone what exactly has to be changed/added so the wrap behaviour of long lines is again the same in Java 7 as in Java 6 and earlier?

I think you have to somehow override the EditorKit but unfortunately I don't how to do this (found the following examples but don't know if it helps and didn't get to adapt it http://java-sl.com/wrap.html )

Thank you very much for your help
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 17 2013
Added on Apr 11 2012
6 comments
12,124 views