Print jtable with Java API

Source: Internet
Author: User

Reference book completed a can print a separate jtable components of the number, I hope to help.

private void printTable() {
   Toolkit kit = Toolkit.getDefaultToolkit(); //获取工具箱
   Properties props = new Properties();
   props.put("awt.print.printer", "durango"); //设置打印属性
   props.put("awt.print.numCopies", "2");
   if (kit != null) {
    //获取工具箱自带的打印对象
    PrintJob printJob = kit.getPrintJob(this, "打印 页面", props);
    if (printJob != null) {
     Graphics pg = printJob.getGraphics(); //获取打印对象的图形环境
     Graphics2D g2 = (Graphics2D) pg; ///
     PageFormat pf = new PageFormat(); ///
     g2.translate(pf.getImageableX(), pf.getImageableY()); ///转换坐标,确定打印边界
     if (pg != null) {
      try {
       pg.dispose(); // Shoot the page to printer
       this.jScrollPane14.printAll(pg); //打印该窗体的组件
      }
      finally {
       pg.dispose(); //注销图形环境pageIndex
      }
     }
     printJob.end(); //结束打印作业
    }
   }
  }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.