JDK-8035278 : Graphics2D.drawLine has wrong endpoint when drawing straight lines
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_8
  • CPU: x86
  • Submitted: 2014-02-16
  • Updated: 2015-01-14
  • Resolved: 2014-12-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b129)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b69, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]

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.

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
No response was received from the submitter. As there is not enough information in this report to make headway it is being closed. If this issue is seen, please open a new report with all necessary information. This report ID can be referenced.
12-05-2014

Mail was sent to submitter requesting more information.
23-04-2014

Need more info
19-02-2014

I am not sure what is meant since I don't see any difference and don't have a screenshot. Maybe the submitter is running on an Intel HD card for which we now enable D3D ? I see they are running Windows 6.3 (aka Windowss 8.1) I'd be interested to know the graphics card model and driver version, and whether -Dsun.java2d.d3d=false makes a difference ?
19-02-2014