Skip to main content

changed wordwrap behaviour in JTextPane for JDK6

No replies
Joined: 2006-10-30


first post ever, i hope this is the right forum to post this in. If not where should i post ?

In JDK6-beta2 I've realised that there has been a change in word wrap in JTextPane (StyledDocument) compared to 1.5.0 and earlier.

A code sample to demonstrate is at the bottom.

If you have a JTextPane, and rows in the available space are completely filled in with characters, with no spaces, obviously you get no word wrap - just a grid of characters.

Now, if you do

to set some of the characters to be coloured

in SE 5.0 - nothing happens except the characters go coloured

but in SE 6.0 - a break is introduced after the coloured text - ie it word wraps like there was a space there.

So i guess ParagraphView is deciding that a Row can be broken after a change in Attributes, if there is no other available break point.

Could anyone point me to where this change is behaviour in JDK6 is documented - or if the new behaviour can be switched off - or some workaround for this.

I've spent quite some time looking through ParagraphView,FlowView, Row, BreakIterator etc, but get lost in the maze.

I suppose i also think this new behaviour is a bug - I can't see that it offers any possible advantage. And it breaks the application that i've worked on for a couple of years!

Any advise or comments would be greatly appreciated... (I hope i've managed to express what the problem is)

The following code and be used to see the difference in the behaviour between the old versions of the SE and the new JDK6 beta.

Run the prog, select a few characters on the second line, and press the highlight button.