JDK-8068822 : Graphics2D.drawLine has wrong endpoint when drawing straight lines
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8,8u25,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_8
  • CPU: x86
  • Submitted: 2014-12-27
  • Updated: 2015-01-14
  • Resolved: 2015-01-14
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 8.1 64 Bit (Microsoft Windows [Version 6.3.9600])

EXTRA RELEVANT SYSTEM CONFIGURATION :
Sony VAIO SVS1512Z9EB
Two graphic Cards 
   Nvidia Geforce GT640MLE - Driver Version: 344.11
   Intel HD 4000                      - Driver Version: 10.18.10.3304 

A DESCRIPTION OF THE PROBLEM :
When drawing a line with Graphics2D under Swing the endpoint of the line seems to be off by one pixel. This seems only to happen when drawing straight horizontal or vertical lines.

This can also be seen in the Ocean L&F where the focus rectangle and the button border is painted wrong.

This never showed up in the current JDK7u51 or previous releases.

Rendering Problem seems to be gone, when NVidia Card is used for Rendering.

New Bug-Report as initial Report was closed: JDK-8035278
I can provide some screenshots of the actual and expected results.

REGRESSION.  Last worked in version 7u51

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Draw some straight horizontal or vertical lines with Graphics2D (Swing). The end-coordinates of the line are off by one pixel.

2. Create a JFrame with one JButton. The focus rectangle and the rollover border are painted wrong (also one additional pixel on the lower left and right corner).


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The focus rectangle of the button should have no pixel errors on the lower left and right corner.

The triangle which is painted on the JPanel should have a width of 5 pixels.
ACTUAL -
Under JDK8:
The button's focus rectangle has two additional pixels in the lower left and right corner.
The triangle on the JPanel has a a width of 6 pixels and not 5 pixels as shown in the example code.


REPRODUCIBILITY :
This bug can be reproduced always.

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


public class CTestFrame extends JFrame {

   private static final long serialVersionUID = 1L;

   public CTestFrame () {

      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setSize(300, 300);
      setLocationRelativeTo(null);

      JButton b = new JButton("A test button");
      add(b, BorderLayout.NORTH);

      JPanel p = new JPanel() {

         private static final long serialVersionUID = 1L;

         @Override
         protected void paintComponent (Graphics g) {
            super.paintComponent(g);

            g.setColor(Color.BLACK);
            g.translate(20, 20);
            int iH = 3;
            int iW = 5;

            for (int i = 0; i < iH; i++ ) {
               g.drawLine(i, i, iW - i - 1, i);
            }
         }

      };
      add(p, BorderLayout.CENTER);

      setVisible(true);

   }

   public static void main (String[] args) {
      SwingUtilities.invokeLater(new Runnable() {

         @Override
         public void run () {
            new CTestFrame();
         }
      });
   }

}

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


Comments
> New Bug-Report as initial Report was closed: JDK-8035278 Yes, of course it was. And it was closed as a duplicate. Please read the full bug thread/chain before filing new bugs.
14-01-2015

is it dup of JDK-8039444 ?
13-01-2015