我正在使用 Java 进行调查,并希望有一个可打印的版本。但是,有些问题不在可视区域内(它们在 JScrollPane 中)。下面是我用于打印的代码,但它只打印 JFrame 的可见部分。请问有人可以帮忙吗?
private void printFrame(){
PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setPrintable(this);
// pop up a dialog box for the end user to fine tune the options.
if ( printerJob.printDialog() )
{
try
{
// render the component onto the printer or print queue.
printerJob.print();
}
catch ( PrinterException e )
{
System.out.println( "Error printing: " + e );
}
}
}
public int print( Graphics gr, PageFormat pageFormat, int pageIndex ){
if ( pageIndex > 0 )
{
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)gr;
g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
double xScale = 0.33;
double yScale = 0.33;
g2d.scale(xScale, yScale);
paint(g2d);
return Printable.PAGE_EXISTS;
}
提前致谢