Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8251836

Some fonts in Java 11 slighly shift upwards as compared to Java 8

XMLWordPrintable

    • 2d
    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      When some text is drawn in swing, we observe that the all characters slightly shift upwards, as compared to Java 8.
      Eg: "Arial" font has this behavior but "MS Gothic" does not.

      REGRESSION : Last worked in version 8

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Write some text in any swing component in Java 8 and Java 11, full screen both windows and compare the position where the text is drawn.
      Please run the attached sample program in Java 8 and Java 11 and full screen both the windows to compare.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Text should be drawn in same position in Java 11 and in Java 8
      ACTUAL -
      Text in Java 11 slightly shifts upwards as compared to Java 8

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.lang.reflect.InvocationTargetException;

      public class HtmlTextDiff extends JFrame {
          private static final int FRAME_WIDTH = 200;
          private static final int FRAME_HEIGHT = 200;
          
          HtmlTextDiff() {
              super(buildTitle());
              setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
              JLabel label = new JLabel("O");
              Font arial = new Font("Arial", Font.PLAIN, 128);
              label.setFont(arial);
              add(label, BorderLayout.CENTER);
          }

          private static void showFrame() {
              HtmlTextDiff problemDemo = new HtmlTextDiff();
              problemDemo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              problemDemo.pack();
              problemDemo.setVisible(true);
          }

          public static void main(String[] args) throws InvocationTargetException, InterruptedException, ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              SwingUtilities.invokeAndWait(HtmlTextDiff::showFrame);
          }

          private static String buildTitle() {
              return "Font viewer - " + property("java.version") + " " + property("sun.java2d.dpiaware");
          }

          private static String property(String s) {
              return s + "=" + System.getProperty(s);
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        1. MS_Gothic.JPG
          MS_Gothic.JPG
          69 kB
        2. HtmlTextDiff.java
          1 kB
        3. Arial.JPG
          Arial.JPG
          71 kB

            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: