United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-7125737 : JTextPane wrap behaviour on long words changed in Java 7

Details
Type:
Bug
Submit Date:
2011-12-29
Status:
Closed
Updated Date:
2012-03-20
Project Name:
JDK
Resolved Date:
2012-01-12
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P2
Resolution:
Not an Issue
Affected Versions:
7
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) Client VM (build 22.0-b10, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Versi??n 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
JTextPane doesn't wrap lines with long words (at least by default) in Java 7.

In previous Java versions (at least 1.3.x to 1.6.x), the default observed line wrapping behaviour for JTextPane was: split into lines at spaces if possible, and if not possible (because there is a very long word that doesn't fit in a single line) then split at some point in the middle of the word.

In 1.7.0_02, the observed behaviour is: split into lines at spaces if possible, but if not possible don't split. Instead, extend the size of the JTextPane (for example, if it's inside a JScrollPane, a horizontal scrollbar will appear).

This breaks programs that were relying in the previous behaviour (for example, when displaying a JTextPane with some text and a long strand of DNA, or a long number, this is important).

REGRESSION.  Last worked in version 6u29

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a JScrollPane to scroll a JTextPane. Place it into a JFrame with some size (e.g. 200x200).

2. Execute it on 1.7. Select the text pane. Type some short words. Then type a very long word. (optionally, compare it with the behaviour in 1.6)

The full source code to do this is below.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect the long word to be split into lines, as in previous versions of Java.
ACTUAL -
The long word is not split into lines: instead, a horizontal scrollbar appears.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

public class WrappingTest extends JFrame
{

	public static void main ( String[] args )
	{
		new WrappingTest();
	}
	
	public WrappingTest ()
	{
		setSize(200,200);
		getContentPane().setLayout(new BorderLayout());
		JTextPane jtp = new JTextPane();
		JScrollPane jsp = new JScrollPane(jtp);
		jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		getContentPane().add(jsp,BorderLayout.CENTER);
		setVisible(true);
	}
	
}
---------- END SOURCE ----------

                                    

Comments



Hardware and Software, Engineered to Work Together