我试图打印JPanel的所有内容,但我无法打印可滚动JTable的所有内容。我可以打印但无法打印Scrollable Jtable的所有数据。&#34 ;打印所有数据的问题不超过"。打印代码
private void Printers(){
PrinterJob job = PrinterJob.getPrinterJob();
job.setJobName("jpanel");
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);
aset.add(new PrinterResolution(300, 300,
PrinterResolution.DPI));
aset.add(DialogTypeSelection.NATIVE);
job.setPrintable (new Printable() {
public int print(Graphics pg, PageFormat pf, int pageNum){
if (pageNum > 0){
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2 = (Graphics2D) pg;
g2.translate(pf.getImageableX()+10, pf.getImageableY()+10);
// g2.scale(1, 1);
jpanel.paint(g2);
return Printable.PAGE_EXISTS;
}
});
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
} catch (PrinterException ex) {
JOptionPane.showMessageDialog(null, "Printing error "+ex);
}
}
}