JDK-4415914 : Font 'Dialog 11pt' does not render correctly in JTextComponent
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.3.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_98
  • CPU: x86
  • Submitted: 2001-02-15
  • Updated: 2001-03-12
  • Resolved: 2001-03-12
Related Reports
Duplicate :  
Description

Name: boT120536			Date: 02/15/2001


java version "1.3.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-beta-b15)
Java HotSpot(TM) Client VM (build 1.3.1beta-b15, mixed mode)

I've tried searching for an exact duplicate of this
bug but couldn't find one. The closest report seems
to be 4140220. Maybe it's related.

===

When using Font("Dialog", Font.PLAIN, 11) as the font
in a JTextComponent, the text will not render properly
- it starts at the wrong position (one pixel to the left
of where it should be). This also has the effect that
the caret will appear "on top" of each character instead
of "just before" it. Other font sizes such as 10pt,
12pt or 13pt do not show this problem. See the
attached test case for a demonstration of the issue
(by the way, NetBeans, which also uses an 11pt font,
is affected too). Again, to clarify, this is not
about wide characters being clipped but the whole
text being somehow shifted one pixel to the left
(when compared to other font sizes).

===

import java.awt.*;
import javax.swing.*;

public class FontProblem extends JFrame {
  public FontProblem() {
    super("FontProblem");

    JPanel pnl = new JPanel();
    pnl.setLayout(new GridBagLayout());

    for (int pt = 13; pt >= 10; pt--) {
      JLabel lbl = new JLabel("JTextField using Font(\"Dialog\", "
        + "Font.PLAIN, " + pt + ")");
      if (pt == 11) {
        lbl.setForeground(Color.red);
      }
      pnl.add(lbl, new GridBagConstraints(
        0, GridBagConstraints.RELATIVE, 1, 1, 0, 0,
        GridBagConstraints.WEST, GridBagConstraints.NONE,
        new Insets(8, 8, 0, 8), 0, 0));

      JTextField tf = new JTextField();
      tf.setFont(new Font("Dialog", Font.PLAIN, pt));
      tf.setText("Demo Text");
      pnl.add(tf, new GridBagConstraints(
        0, GridBagConstraints.RELATIVE, 1, 1, 1, 0,
        GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
        new Insets(0, 8, 0, 8), 0, 0));
    }

    pnl.add(Box.createGlue(), new GridBagConstraints(
      0, GridBagConstraints.RELATIVE, 1, 1, 1, 1,
      GridBagConstraints.CENTER, GridBagConstraints.BOTH,
      new Insets(8, 8, 8, 8), 0, 0));

    setContentPane(pnl);

    pack();
    setLocation((getToolkit().getScreenSize().width - getWidth()) / 2,
      ((getToolkit().getScreenSize().height) - getHeight()) / 2);
  }

  public static void main(String[] args) {
    new FontProblem().setVisible(true);
  }
}
(Review ID: 117062) 
======================================================================

Comments
EVALUATION The problem is reproducible on 1.1.8, 1.2, 1.3, 1.3.1, 1.4 on Win32 and solaris. It might be that it's just a characteristic of the font we're using. It's not reproducible with pure awt applications on Solaris but it is on Win32. Since it's not a regression and it's a P4 it won't be fixed in Ladybird. dmitri.trembovetski@eng 2001-02-15
15-02-2001