JDK-8080135 : JTextpane visibleEditorRect has no effect on java 7 and java 8
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-05-08
  • Updated: 2016-01-18
  • Resolved: 2015-05-13
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [S��r��m 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
The problem occurs when BasicTextPaneUI getVisibleEditorRect method overriden. At the version java 6 everything goes as expected but at java 7 and the later version jtextpane does not care about the area defined by getVisibleEditorRect method.

REGRESSION.  Last worked in version 6u45

ADDITIONAL REGRESSION INFORMATION: 
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the code given in test code both java 6 and java 8


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
expected result is , at the visibleRect area border Jtextpane must break the line to next one
ACTUAL -
at java 6 above code runs as expected but at java 8 the line overflow the visibleEditorRect area

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Rectangle;

import javax.swing.JFrame;
import javax.swing.JTextPane;
import javax.swing.plaf.basic.BasicTextPaneUI;

public class TextPaneBug {
	
	public static void main(String[] args) {
		JFrame f = new JFrame() ;
		JTextPane text = new BugTextPane() ;
		f.add(text);
		text.setText("mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm");
		f.setExtendedState(JFrame.MAXIMIZED_BOTH);
		f.setVisible(true);
	}

	static class BugTextPane extends JTextPane
	{
		public BugTextPane() {		
			setUI(new BasicTextPaneUI(){
				@Override
				protected Rectangle getVisibleEditorRect() {
					Rectangle r = super.getVisibleEditorRect() ;
					Rectangle newr = new Rectangle(r.width / 2 - 300 , r.height/2 - 300 , 600 ,600) ;
					return newr;
				}
				protected void paintSafely(java.awt.Graphics g) {
					super.paintSafely(g);
					Rectangle r = getVisibleEditorRect() ;
					g.drawRect(r.x,r.y,r.width,r.height);
				};
			}
			
				);
		}
	}
}
---------- END SOURCE ----------


Comments
VisibleEditorRect is taken into account but in the proposed scenario the text is a single word longer then the requested VisibleEditorRect. Single word should not be broken in JTextPane. The explanation can be found here JDK-6539700 or here JDK-7125737.
13-05-2015