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