怎么打印很清单?

时间:2018-01-25 17:32:44

标签: java

美好的一天,我想问你是否知道如何在gridbaglayout上打印非常大的列表内容,因为当我打印它时只打印你在窗口中看到的内容,建议如何改进它,或者应该我用另一种语言? enter image description here

代码打印:

 //Clase Imprimir
 class Imprimir implements Printable {

public void Imprime() {

    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pagef = job.defaultPage();
    Paper paper = new Paper();
    double margin = 10; // half inch
    paper.setImageableArea(margin, margin , paper.getWidth() - margin * 2, 
            paper.getHeight() - margin * 2);
    pagef.setOrientation( PageFormat.LANDSCAPE );
    pagef.setPaper( paper );
    Book bk = new Book();
    bk.append( this, pagef );
    job.setPageable( bk );
    boolean ok = job.printDialog();

    if ( ok ) {
        try {
            job.print();
        } catch ( PrinterException ex ) {
            // The job did not successfully complete
        }
    }
} // Fin del metodo imprime

public int print( Graphics g, PageFormat pf, int page ) throws PrinterException {

    if ( page > 3 ) { // We have only one page, and 'page' is zero-based
        System.out.printf( "page = %d\n", page );
        return NO_SUCH_PAGE;
    }

      // User (0,0) is typically outside the imageable area, so we must translate
      // by the X and Y values in the PageFormat to avoid clipping

    Graphics2D g2d = ( Graphics2D ) g;

    g2d.translate( pf.getImageableX(), pf.getImageableY() );

       // Now print the window and its visible contents
    //GridBagLayoutTree.frame.printAll( g2d ); //Imprime la ventana completa
    //GridBagLayoutTree.frame.print(g2d); //Imprime el contenedor dentro de la ventana    
    GridBagLayoutTree.frame.printComponents( g2d ); //Imprime el contenedor dentro de la ventana

       //tell the caller that this page is part of the printed document
    return PAGE_EXISTS;
 }    // Fin del metodo print
}    // Fin de la clase Imprimir

0 个答案:

没有答案