0

我正在尝试打印一个包含两个表格的 jpanel,但是表格的宽度大于表格出现的页面的问题。有没有让表格适合页面宽度,或者我应该自己调整表格的大小?

这是我所做的:

 PrinterJob job = PrinterJob.getPrinterJob();
 job.setJobName("test");

 job.setPrintable (new Printable() {    
        @Override
    public int print(Graphics pg, PageFormat pf, int pageNum) throws PrinterException{
        if (pageNum > 0){
        return Printable.NO_SUCH_PAGE;
        }


        Graphics2D g2 = (Graphics2D) pg;
        g2.translate(pf.getImageableX(), pf.getImageableY());
        jPanel1.print(g2);

         // jTable1.print(JTable.PrintMode.FIT_WIDTH, null, null);
        return Printable.PAGE_EXISTS;
    }
 });
 boolean ok = job.printDialog();
 if (ok) {
     try {
          job.print();
     } catch (PrinterException ex) {

     }
 }
4

0 回答 0