JDK-8257810 : Only First page are printed in JTable.scrollRectToVisible
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 9,11,14,15
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2020-12-04
  • Updated: 2022-09-14
  • Resolved: 2022-05-26
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 19
19 b25Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Microsoft Windows [Version 10.0.19042.630]
openjdk version "15.0.1" 2020-10-20
OpenJDK Runtime Environment AdoptOpenJDK (build 15.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 15.0.1+9, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
When printing a JTable and the table sits inside a JScrollPane and the table is scrolled down only the first pages are printet
javax.swing.TablePrintable.print(Graphics graphics, PageFormat pageFormat, int pageIndex) returns NO_SUCH_PAGE because of 
            if (!((table.getBounds()).intersects(clip))) {
                return NO_SUCH_PAGE;
            }

Java 8 does not have this check and it prints all pages.

REGRESSION : Last worked in version 8

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program and print to ie. a PDF printer.
Only the first page is printed.
Disable the line with the comment "Enabling this line..." and the entire table prints.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All pages are printed
ACTUAL -
Only the first page is printed.

---------- BEGIN SOURCE ----------
public class TableTest {
	public static void main(String... args) {
		SwingUtilities.invokeLater(() -> {
			TableModel dataModel = new AbstractTableModel() {
				@Override public int getColumnCount() {	return 10; }
				@Override public int getRowCount() {return 1000; }
				@Override public Object getValueAt(int row, int col) { return Integer.valueOf(0==col?row+1:row * col);	}
			};
			JTable table = new JTable(dataModel) {
				@Override public Rectangle getBounds() {
					Rectangle bounds = super.getBounds();
					// bounds.y=0; // Workaround - enable this line
					return bounds;
				}
			};
			JScrollPane scrollpane = new JScrollPane(table);
			table.scrollRectToVisible(table.getCellRect(table.getRowCount()-1, 0, false)); // Enabling this line makes print only print 90 rows in Java 14
			JFrame f = new JFrame("Table test Java version: "+ System.getProperty("java.version"));
			f.add(scrollpane);
			f.setSize(1000, 800);
			f.setLocationRelativeTo(null);f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			f.setVisible(true);
			try {
				table.print();
			} catch (PrinterException e) {
				e.printStackTrace();
			}
		});
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Enable the line marked with comment Workaround

FREQUENCY : always



Comments
Changeset: f710393e Author: Prasanta Sadhukhan <psadhukhan@openjdk.org> Date: 2022-05-26 06:32:28 +0000 URL: https://git.openjdk.java.net/jdk/commit/f710393e352b0945ad64df3ee5ccd34f082c2b63
26-05-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/8141 Date: 2022-04-07 09:17:02 +0000
07-04-2022

Checked with attached test case on Windows 10, Issue is reproducible Test Result: ========= 8u271: Pass 11: Fail 11.0.9: Fail 15.0.l: Fail 16ea27: Fail
07-12-2020