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

[macosx] JTable grid lines are incorrectly positioned on HiDPI display

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b153
    • CPU:
      x86
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      JTable grid lines are positioned 1 pixel too high or too far left on a 2x HiDPI display.

      The grid lines are drawn using drawLine at x-1 or y-1. This produces the intended effect on a 1x display, which is a 1 px line between x-1 and x or between y-1 and y. On a HiDPI display, the line is centered around x-1 or y-1. Should use drawRect.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JTable that displays grid lines and has a non-opaque cell renderer. View on a HiDPI display.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The grid lines should be painted between the cell backgrounds.
      ACTUAL -
      The grid lines are painted 1 pixel too high or too far left, and are thus partially overlapped by the cell backgrounds.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

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

      public class TestTableGrid
      {
      JFrame fr;

      public TestTableGrid()
      {
      fr = new JFrame("Test Table Grid");

      TableModel dataModel = new AbstractTableModel() {
      public int getColumnCount() { return 10; }
      public int getRowCount() { return 10;}
      public Object getValueAt(int row, int col) { return new Integer(row*col); }
      };

      DefaultTableCellRenderer r = new DefaultTableCellRenderer();
      r.setOpaque(true);
      r.setBackground(Color.YELLOW);

      JTable t = new JTable(dataModel);
      t.setDefaultRenderer(Object.class, r);
      t.setGridColor(Color.BLACK);
      t.setShowGrid(true);
      t.setShowHorizontalLines(true);
      t.setShowVerticalLines(true);
      fr.setContentPane(t);
      fr.setLocation(200, 200);
      fr.pack();
      fr.setVisible(true);
      }

      public static void main(String args[])
      {
      new TestTableGrid();
      }
      }

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

        Attachments

          Activity

            People

            Assignee:
            alexsch Alexandr Scherbatiy
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: