有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java打印可滚动JTable的所有数据

我正在尝试打印JPanel的所有内容,但无法打印可滚动JTable的所有内容。我可以打印但无法打印可滚动Jtable的所有数据。“打印所有数据的问题不超过此值”。打印代码

    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);
          }

        }

    }

Here is the image


共 (0) 个答案