RFR: 8210807: Printing a JTable with a JScrollPane prints table without rows populated [v8]

Abhishek Kumar abhiscxk at openjdk.org
Fri Nov 10 11:16:09 UTC 2023


On Fri, 10 Nov 2023 09:14:25 GMT, Tejesh R <tr at openjdk.org> wrote:

>> `BackingStore` uses its own Graphics to Paint the Image. This is fine when we want to paint it on a Window/Frame, but fails to print. Since `WPathGraphics` is used for Printing, backing store fails to print it and backing store uses newly created `SunGraphics2D` always. The proposed fix is to ignore `backingstore` graphics if passed on Graphics is different from `SunGraphics2D` which ensures the Image is painted on Window and also printed when required. 
>> The fix is tested in CI and doesn't cause any regression. The test is verified manually.
>
> Tejesh R has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Review fix

Minor findings.

test/jdk/javax/swing/JTable/JTableScrollPrintTest.java line 48:

> 46:  * @library /java/awt/regtesthelpers
> 47:  * @build PassFailJFrame
> 48:  * @summary Test to check if JTable can be printed when it is

I think summary should be..
Suggestion:

 * @summary Test to check if JTable can be printed when JScrollPane added to it.

test/jdk/javax/swing/JTable/JTableScrollPrintTest.java line 68:

> 66:     }
> 67: 
> 68:     public static void initialize() throws Exception{

Suggestion:

    public static void initialize() throws Exception {

test/jdk/javax/swing/JTable/JTableScrollPrintTest.java line 78:

> 76:         TestTable testTable = new TestTable(true);
> 77:         frame = new JFrame("JTable Print Test");
> 78:         passFailJFrame = new PassFailJFrame("Test Instructions", INSTRUCTIONS, 5L, 6, 35);

If you want then you can use builder pattern for configuring PassFailJFrame.

test/jdk/javax/swing/JTable/JTableScrollPrintTest.java line 122:

> 120:     static class PrintUtilities implements Printable {
> 121:         private Component componentToBePrinted;
> 122:         public void printComponent(Component c, String jobname) {

Blank line before this.

test/jdk/javax/swing/JTable/JTableScrollPrintTest.java line 137:

> 135:             // set margins to 1/2"
> 136:             Paper p = new Paper();
> 137:             p.setImageableArea(36, 36, p.getWidth()-72, p.getHeight()-72);

Suggestion:

            p.setImageableArea(36, 36, p.getWidth() - 72, p.getHeight() - 72);

test/jdk/javax/swing/JTable/JTableScrollPrintTest.java line 158:

> 156:                 Graphics2D g2d = (Graphics2D)g;
> 157:                 g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
> 158:                 Component c= componentToBePrinted;

Suggestion:

                Component c = componentToBePrinted;

test/jdk/javax/swing/JTable/JTableScrollPrintTest.java line 163:

> 161:                 double panelX= c.getWidth();
> 162:                 double panelY= c.getHeight();
> 163:                 float imageableX = (float) pageFormat.getImageableWidth()-1;

Suggestion:

                float imageableX = (float) pageFormat.getImageableWidth() - 1;

test/jdk/javax/swing/JTable/JTableScrollPrintTest.java line 164:

> 162:                 double panelY= c.getHeight();
> 163:                 float imageableX = (float) pageFormat.getImageableWidth()-1;
> 164:                 float imageableY = (float) pageFormat.getImageableHeight()-1;

Suggestion:

                float imageableY = (float) pageFormat.getImageableHeight() - 1;

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

PR Review: https://git.openjdk.org/jdk/pull/16552#pullrequestreview-1724556100
PR Review Comment: https://git.openjdk.org/jdk/pull/16552#discussion_r1389259387
PR Review Comment: https://git.openjdk.org/jdk/pull/16552#discussion_r1389260014
PR Review Comment: https://git.openjdk.org/jdk/pull/16552#discussion_r1389261148
PR Review Comment: https://git.openjdk.org/jdk/pull/16552#discussion_r1389261967
PR Review Comment: https://git.openjdk.org/jdk/pull/16552#discussion_r1389263199
PR Review Comment: https://git.openjdk.org/jdk/pull/16552#discussion_r1389263836
PR Review Comment: https://git.openjdk.org/jdk/pull/16552#discussion_r1389264335
PR Review Comment: https://git.openjdk.org/jdk/pull/16552#discussion_r1389264651


More information about the client-libs-dev mailing list