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

Windows L&F on scaled display uses tiny control font

XMLWordPrintable

    • 9
    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      In a Swing application using Windows Look&Feel on a scaled display (HiDPI @ 150%), the default font for controls like labels and text fields is very small (7 pt) and hardly readable, while other GUI elements like menus use a decently sized default font (12 pt).
      The problem can be traced to the output of the native method sun.awt.windows.WDesktopProperties.getWindowsParameters(), which returns various fonts supposed to be set by the OS. Most of them are Segoe UI 12 on my system regardless of display scaling, but the control font returned is Tahoma 11 on unscaled displays and Tahoma 7 on 150 % scaling. (Why is it a different font, anyway?)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use a Swing application on Windows which uses default fonts and Windows LookAndFeel (e. g. the attached reproducer).
      In the Windows settings, scale the display to 150 % or higher.
      Run the application.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      All controls and parts of the GUI have readable fonts which have reasonable size relations among each other.
      ACTUAL -
      Fonts on labels, text fields, tables and other controls are tiny, while the fonts used for menus are normal size.

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

      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JPanel;
      import javax.swing.JTextField;
      import javax.swing.UIManager;

      public class FontScalingBugReproducer
              extends JFrame {

          private static final long serialVersionUID = 1L;

          public static void main(String[] args)
                  throws Exception {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              JFrame window = new JFrame();
              buildGui(window);
              window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              window.setLocation(800, 500);
              window.pack();
              window.setVisible(true);
          }

          private static void buildGui(JFrame window) {
              window.setTitle("Font scaling bug reproducer");

              JMenuBar menuBar = new JMenuBar();
              menuBar.add(new JMenu("Edit"));
              menuBar.add(new JMenu("View"));
              window.setJMenuBar(menuBar);

              JPanel panel = new JPanel();

              JLabel label = new JLabel();
              label.setText("Default JLabel font is " + printFont(label));
              panel.add(label);

              JTextField text = new JTextField();
              text.setText("Default JTextField font is " + printFont(text));
              panel.add(text);

              window.add(panel);
          }

          private static String printFont(Component comp) {
              return comp.getFont().getFontName() + " " + comp.getFont().getSize();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Override default fonts for the following keys in UIDefaults:
                      "Button.font",
                      "CheckBox.font",
                      "ComboBox.font",
                      "EditorPane.font",
                      "FormattedTextField.font",
                      "Label.font",
                      "List.font",
                      "RadioButton.font",
                      "Panel.font",
                      "PasswordField.font",
                      "ProgressBar.font",
                      "ScrollPane.font",
                      "Slider.font",
                      "Spinner.font",
                      "TabbedPane.font",
                      "Table.font",
                      "TableHeader.font",
                      "TextField.font",
                      "TextPane.font",
                      "TitledBorder.font",
                      "ToggleButton.font",
                      "Tree.font",
                      "Viewport.font"

      FREQUENCY : always


            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: