United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6459404 jTextPane/jEditorPane text space higher than before
JDK-6459404 : jTextPane/jEditorPane text space higher than before

Details
Type:
Bug
Submit Date:
2006-08-11
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
windows_xp
Sub-Component:
2d
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
<build 1.6.0-rc-b94, mixed mode, sharing>

ADDITIONAL OS VERSION INFORMATION :
Windows XP - Professional - Version 2002 Service Pack 2

EXTRA RELEVANT SYSTEM CONFIGURATION :
Laptop IBM T42P

A DESCRIPTION OF THE PROBLEM :
I use a jEditorPane to display some RTF text, no problem at all since the JDK 1.3 until JDK 1.5. But when I try to display some saved documents with Mustang as JDK, it seems that the height of each line has been increased. The consequence of this change is that a text cannot appear completely anymore (I don???t use any jScrollPane, in fact the size of the editorPane is fixed in advance definitively). After analyzing the values returned by some methods provided within the class BoxView, I???ve noticed that the height of the spans has been increased as compared to the values returned before.

for example:

Font used: Arial size 11
Jdk 1.5 :  Span = 14
Mustang: Span =15

Font used: Arial size 16

Jdk 1.5 :  Span = 19
Mustang: Span =21


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Put a jEdtorPane into a frame and launch this simple application under the jdk1.5 and after the latest release of mustang. Compare directly the result on the screen. Try to enter a text composed of several lines (Arial font)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
By using the jdk 1.5 or previous the text takes less height space than using mustang

---------- BEGIN SOURCE ----------

main class: test.java
*************************************

package editor;

import java.awt.Toolkit;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.awt.Dimension;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class test {
    boolean packFrame = false;

    /**
     * Construct and show the application.
     */
    public test() {
        Frame1 frame = new Frame1();
        // Validate frames that have preset sizes
        // Pack frames that have useful preferred size info, e.g. from
their layout
        if (packFrame) {
            frame.pack();
        } else {
            frame.validate();
        }

        // Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = frame.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        frame.setLocation((screenSize.width - frameSize.width) / 2,
                          (screenSize.height - frameSize.height) / 2);
        frame.setVisible(true);
    }

    /**
     * Application entry point.
     *
     * @param args String[]
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.

getSystemLookAndFeelClassName());
                } catch (Exception exception) {
                    exception.printStackTrace();
                }

                new test();
            }
        });
    }
}


*************************************

Second classe Frame1:

*************************************

package editor;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.*;
import javax.swing.text.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Frame1 extends JFrame {
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout();
    JTextPane editor;
    String text="The Caterpillar and Alice looked at each other for some
time in silence:  at last the Caterpillar took the hookah out of its mouth,
and addressed her in a languid, sleepy voice.";

    public Frame1() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    /**
     * Component initialization.
     *
     * @throws java.lang.Exception
     */
    private void jbInit() throws Exception {
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(null);
        setSize(new Dimension(400, 300));
        setTitle("Frame Title");
        editor = new JTextPane();

        editor.setBounds(10,10,150,150);
        contentPane.add(editor);

        MutableAttributeSet attr = new SimpleAttributeSet();
        StyleConstants.setFontFamily(attr, "Arial");
        StyleConstants.setFontSize(attr, 11);
        editor.getDocument().insertString(0,text,attr);
    }
}
---------- END SOURCE ----------

REPRODUCIBILITY :
This bug can be reproduced always.

Release Regression From : 5.0u7
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

                                    

Comments
EVALUATION

Not reproducible under Linux.
The screenshots show 1.6 uses slightly larger font. May be that Windows algorithm for font resolution has changed in 1.6.
                                     
2006-08-14
EVALUATION

In this case Swing is getting the metrics for the Dialog composite font instead of Arial.
It affects only the font that is Slot 0 of Dialog which is Arial on windows and solaris
and Lucida Sans Regular Linux if that matters. 

It was introduced by the b45 fix (July 2005)  for :

6289072: Japanese bold fonts are displayed as square boxes [doug.felt, igor.nekrestyanov]

As of some while ago the swing text components - in order to fix a problem with chinese
tooltips showing as missing glyphs - started to use some code 2D added for swing
that adds dialog as a fallback font for the physical font.

The problem came in 6289072 when the code that creates these special composites
explicitly checked for the case when it was being asked to create a fallback for a font
where that font was slot zero of Dialog. Previously a comment indicated that it should
just return dialog in this case but the code did not do that. Now it does and this means
it gets dialog's metrics, instead of Arial's.
This is wrong. These composites are supposed to use the metrics of the primary font,
not the composite and this special case code thwarts that.

The fix is simply to undo that part of the 6289072 fix which is a few lines of
code to delete.

Note that this isn't a general problem: it would not affect other fonts, or
fonts in general: only using the one specific font which uses this internal
fallback code.
                                     
2006-08-23



Hardware and Software, Engineered to Work Together