11/*
2- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3636import javax .swing .JScrollPane ;
3737import javax .swing .JTable ;
3838import javax .swing .JViewport ;
39- import javax .swing .SwingUtilities ;
4039import javax .swing .table .DefaultTableModel ;
4140
4241/*
4342 * @test
4443 * @key headful
45- * @bug 8210807
44+ * @bug 8210807 8322140
4645 * @library /java/awt/regtesthelpers
4746 * @build PassFailJFrame
4847 * @summary Test to check if JTable can be printed when JScrollPane added to it.
4948 * @run main/manual JTableScrollPrintTest
5049 */
5150
5251public class JTableScrollPrintTest {
53- public static JFrame frame ;
54- public static PassFailJFrame passFailJFrame ;
55-
5652 public static void main (String [] args ) throws Exception {
57- SwingUtilities .invokeAndWait (() -> {
58- try {
59- initialize ();
60- } catch (Exception e ) {
61- throw new RuntimeException (e );
62- }
63- });
64- passFailJFrame .awaitAndCheck ();
65- }
66-
67- public static void initialize () throws Exception {
68- final String INSTRUCTIONS = """
53+ String INSTRUCTIONS = """
6954 Instructions to Test:
7055 1. Print table onto Paper/PDF, using the Print Dialog.
7156 2. If entire table is printed, then the Test is PASS.
7257 3. If table is partially printed without table cells,
7358 then the Test is FAIL.
7459 """ ;
75- TestTable testTable = new TestTable (true );
76- frame = new JFrame ("JTable Print Test" );
77- passFailJFrame = new PassFailJFrame ("Test Instructions" , INSTRUCTIONS , 5L , 6 , 35 );
60+ PassFailJFrame .builder ()
61+ .title ("Test Instructions" )
62+ .instructions (INSTRUCTIONS )
63+ .rows (6 )
64+ .columns (35 )
65+ .testUI (JTableScrollPrintTest ::initialize )
66+ .build ()
67+ .awaitAndCheck ();
68+ }
7869
70+ public static JFrame initialize () {
71+ TestTable testTable = new TestTable (true );
72+ JFrame frame = new JFrame ("JTable Print Test" );
7973 PassFailJFrame .addTestWindow (frame );
8074 PassFailJFrame .positionTestWindow (frame , PassFailJFrame .Position .VERTICAL );
8175 frame .add (testTable );
8276 frame .pack ();
8377 frame .setVisible (true );
8478 PrintUtilities printerJob = new PrintUtilities (testTable );
8579 printerJob .print ("Test BackingStore Image Print" );
80+ return frame ;
8681 }
8782
8883 public static class TestTable extends JPanel {
@@ -103,7 +98,7 @@ public TestTable(Boolean useScrollPane) {
10398
10499 JTable table = new JTable (model );
105100
106- if (useScrollPane == true ) {
101+ if (useScrollPane ) {
107102 JScrollPane sp = new JScrollPane (table ,
108103 JScrollPane .VERTICAL_SCROLLBAR_ALWAYS ,
109104 JScrollPane .HORIZONTAL_SCROLLBAR_AS_NEEDED );
@@ -117,7 +112,7 @@ public TestTable(Boolean useScrollPane) {
117112 }
118113
119114 static class PrintUtilities implements Printable {
120- private Component componentToBePrinted ;
115+ private final Component componentToBePrinted ;
121116
122117 public void printComponent (Component c , String jobname ) {
123118 new PrintUtilities (c ).print (jobname );
0 commit comments