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

Drawings with Graphics are distorted under certain conditions in Windows

XMLWordPrintable

    • 9
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Monitor: Dell P2416D 23.8 inch, 2560 x 1440 pixels
      OS: Windows 10 64 bit
      Java version: 10.0.1

      A DESCRIPTION OF THE PROBLEM :
      Under Windows 10 settings "All settings > System > Display" there is an option to scale Windows elements to greater than 100% (default and recommended settings are 125%). When you choose the scaling 125% for example, drawings with Graphics are distorted. Rectangles are bigger than they should be, and when trying to draw single pixels, there are some pixels that you cannot draw on.

      When running the following code example, the rectangle should have an exact width and height of 20 pixels, but instead it has a width and height of 25 pixels. And there should be a 9 pixels long line drawn with 9 single pixels, but instead the line is broken two times.

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

      public class Programm1
      {
      public static void main(String[] args)
      {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.add(new Programm1Component());

      frame.pack();
      frame.setVisible(true);
      }
      }

      class Programm1Component extends JComponent
      {
      public void paintComponent(Graphics g)
      {
      g.fillRect(1,1,20,20);
      g.drawRect(1,25,0,0);
      g.drawRect(2,25,0,0);
      g.drawRect(3,25,0,0);
      g.drawRect(4,25,0,0);
      g.drawRect(5,25,0,0);
      g.drawRect(6,25,0,0);
      g.drawRect(7,25,0,0);
      g.drawRect(8,25,0,0);
      g.drawRect(9,25,0,0);

      }

      public Dimension getPreferredSize()
      {
      return new Dimension(300,300);
      }
      }

      REGRESSION : Last worked in version 8u171

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Windows settings "All settings > System > Display" scaling to "125%"
      2) compile and run with JDK version 10.0.1

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A frame with a rectangle with a width and height of 20 pixels will be shown, and under it a 9 pixels long line.
      ACTUAL -
      A frame with a rectangle with a width and height of 25 pixels will be shown, and 3 interrupted lines under that rectangle.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      public class Programm1
      {
      public static void main(String[] args)
      {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.add(new Programm1Component());

      frame.pack();
      frame.setVisible(true);
      }
      }

      class Programm1Component extends JComponent
      {
      public void paintComponent(Graphics g)
      {
      g.fillRect(1,1,20,20);
      g.drawRect(1,25,0,0);
      g.drawRect(2,25,0,0);
      g.drawRect(3,25,0,0);
      g.drawRect(4,25,0,0);
      g.drawRect(5,25,0,0);
      g.drawRect(6,25,0,0);
      g.drawRect(7,25,0,0);
      g.drawRect(8,25,0,0);
      g.drawRect(9,25,0,0);

      }

      public Dimension getPreferredSize()
      {
      return new Dimension(300,300);
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Set the Windows settings "All settings > System > Display" scaling to "100%" (instead of the default 125%).

      FREQUENCY : always


        1. Programm1.java
          0.7 kB
          Pardeep Sharma
        2. results.png
          8 kB
          Pardeep Sharma

            rmahajan Rajat Mahajan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: