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

LineBorder does not scale correctly

XMLWordPrintable

    • b22
    • 20
    • b06
    • x86_64
    • windows

        ADDITIONAL SYSTEM INFORMATION :
        Windows 11
        JDK 21.0.3

        A DESCRIPTION OF THE PROBLEM :
        LineBorder does not scale correctly. With my OS set to 150% scale for example, the width of the LineBorder is the same as with my OS at 100% scale.

        The bug is new since JDK 17.0.3. It works as expected in that version.

        I believe the bug is in the following line of code in javax.swing.border.LineBorder:

          int offs = this.thickness * (int) scaleFactor;

        Note how scaleFactor is cast to an int before being used, thus losing the fractional part! This means that a scaling factor of 1.5 will result in an effective scale factor of 1. And a scale factor of 0.5 will result in an effective scale factor of 0 (making the border disappear entirely).

        REGRESSION : Last worked in version 17

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Set your OS scaling to 150% via the OS settings
        2. Run the code below
        3. Print screen the Java app and paste it to a paint program
        4. Measure the width of the red border in pixels

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The border is 15 pixels wide
        ACTUAL -
        The border is 10 pixels wide

        ---------- BEGIN SOURCE ----------
        import javax.swing.*;
        import javax.swing.border.LineBorder;
        import java.awt.*;

        public class LineBorderBug {
            public static void main(String[] args) {
                JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setSize(100, 100);
                JPanel panel = new JPanel();
                panel.setBorder(new LineBorder(Color.RED, 10));
                frame.add(panel);
                frame.setVisible(true);
            }
        }
        ---------- END SOURCE ----------

        FREQUENCY : always

              rmahajan Rajat Mahajan (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: