JTextpane does not respect visibleEditorRect since java 8

Execute the below code of both java 6 and java 8 and see the result. Line breaks work within visibleEditorRect on java 6, but in java 8 the line overflows boundaries. Is there any workaround for this problem.

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);
            };
        }

            );
    }
}
}

      

+3


source to share


1 answer


I am resolving the problem of reverting the violation behavior in java 6 functionality. Overwriting the methods getBreakWeight

and getBreakSpot

by copying from java 6 in the LabelView extension is enough.



+1


source







All Articles