RFR: 8311031: JTable header border vertical lines are not aligned with data grid lines

Abhishek Kumar abhiscxk at openjdk.org
Tue Jul 4 11:31:00 UTC 2023


On Tue, 4 Jul 2023 11:01:27 GMT, Tejesh R <tr at openjdk.org> wrote:

> The header border uses `g.drawLine` whereas the JTable data grid lines uses `SwingUtilities2.drawVLine` and `SwingUtilities2.drawHLine` to draw horizontal and vertical lines. The SwingUtilities2 uses `Graphics.fillRect` which contributes to the difference between the position of these two lines which happens/visible at higher ui scaling (difference in alignment between vertical lines of these two). The fix propose to use the same methods for metal L&F of JTable header border paint. 
> CI testing shows green.
> 
> ![image](https://github.com/openjdk/jdk/assets/94159358/f6d1d822-55ba-4ad3-9914-d3f68b67a6c5)

src/java.desktop/share/classes/javax/swing/plaf/metal/MetalBorders.java line 1111:

> 1109: 
> 1110:             g.setColor( MetalLookAndFeel.getControlDarkShadow() );
> 1111:             SwingUtilities2.drawVLine(g,w-1, 0, h-1);

Suggestion:

            SwingUtilities2.drawVLine(g, w-1, 0, h-1);

src/java.desktop/share/classes/javax/swing/plaf/metal/MetalBorders.java line 1112:

> 1110:             g.setColor( MetalLookAndFeel.getControlDarkShadow() );
> 1111:             SwingUtilities2.drawVLine(g,w-1, 0, h-1);
> 1112:             SwingUtilities2.drawHLine(g,1,  w-1,h-1);

Suggestion:

            SwingUtilities2.drawHLine(g, 1, w-1, h-1);

src/java.desktop/share/classes/javax/swing/plaf/metal/MetalBorders.java line 1114:

> 1112:             SwingUtilities2.drawHLine(g,1,  w-1,h-1);
> 1113:             g.setColor( MetalLookAndFeel.getControlHighlight() );
> 1114:             SwingUtilities2.drawHLine(g,0, w-2,0 );

Suggestion:

            SwingUtilities2.drawHLine(g, 0, w-2, 0 );

src/java.desktop/share/classes/javax/swing/plaf/metal/MetalBorders.java line 1115:

> 1113:             g.setColor( MetalLookAndFeel.getControlHighlight() );
> 1114:             SwingUtilities2.drawHLine(g,0, w-2,0 );
> 1115:             SwingUtilities2.drawVLine(g,0, 0, h-2);

Suggestion:

            SwingUtilities2.drawVLine(g, 0, 0, h-2);

test/jdk/javax/swing/JTableHeader/TableHeaderBorderPositionTest.java line 1:

> 1: /*

Is it possible to make an automated test by comparing pixel colors of images before and after fix?

test/jdk/javax/swing/JTableHeader/TableHeaderBorderPositionTest.java line 51:

> 49:                 2. Check if the Table header border vertical lines are
> 50:                 aligned with table data grid lines.
> 51:                 3. If there is a miss-match between them press FAIL,

Suggestion:

                3. If there is a mismatch between them press FAIL,

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14766#discussion_r1251897705
PR Review Comment: https://git.openjdk.org/jdk/pull/14766#discussion_r1251898060
PR Review Comment: https://git.openjdk.org/jdk/pull/14766#discussion_r1251898963
PR Review Comment: https://git.openjdk.org/jdk/pull/14766#discussion_r1251899506
PR Review Comment: https://git.openjdk.org/jdk/pull/14766#discussion_r1251891816
PR Review Comment: https://git.openjdk.org/jdk/pull/14766#discussion_r1251890824



More information about the client-libs-dev mailing list