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

[hidpi] HTML-JLabel font sizes are broken in Windows L&F with HiDPI display

    Details

      Description

      When manipulating the font size of an HTML JLabel using the <font size='+1'> tag, the displayed font actually gets smaller, instead of larger. This is probably due to the code starting the calculation at a smaller font-size than the non-HTML JLabel.

      This only happens with the Windows Look and Feel.

      Steps to reproduce:
      Run the code:
      -----------------------
      import javax.swing.*;
      import java.awt.*;

      import static javax.swing.JFrame.EXIT_ON_CLOSE;

      public class JTextAreaTest {

          public static void main(String[] args) {
              try {
                  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch (Exception e) {
                  e.printStackTrace();
              }
              SwingUtilities.invokeLater(() -> {
                  final JFrame frame = new JFrame();
                  frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
                  frame.setBounds(500, 500, 300, 150);
                  frame.setLayout(new BorderLayout());
                  final JLabel label = new JLabel("Regular Label");
                  frame.add(label, BorderLayout.NORTH);
                  final JLabel htmlLabel0 = new JLabel("<html><font size='+1'>HTML Label +1</font></html>");
                  final JLabel htmlLabel1 = new JLabel("<html><font size='+0'>HTML Label +0</font></html>");
                  frame.add(htmlLabel0, BorderLayout.CENTER);
                  frame.add(htmlLabel1, BorderLayout.SOUTH);
                  frame.setVisible(true);
              });
          }
      }

      --------------------------

      Attached screenshot demonstrates that the +1 font size is actually slightly smaller than the regular font. Also +0 is tiny, even though it should have no effect whatsoever.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                hschreiber Hendrik Schreiber
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: