1. 首页
  2. 编程语言
  3. Java
  4. java打印form

java打印form

上传者: 2019-04-19 18:32:07上传 DOC文件 22KB 热度 35次
java程序打印整个框架 JAVA实现FORM的打印 import java.awt.Container; import java.awt.Graphics; import java.awt.PrintJob; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Properties; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class FF extends JFrame { JPanel jp; public FF(int x,int y){ this.setDefaultCloseOperation(3); this.setSize(x,y);//最好用变量伟值 } public void d(JPanel jp){ this.jp=jp; this.add(jp); this.setVisible(true);//必须设置为可见,估计JAVA打印时只能捕捉到屏幕上处在开启状态的程序 print(this); } public void print(JFrame frame){ Container container=frame.getContentPane(); Properties prop=new Properties(); PrintJob job = getToolkit().getPrintJob(frame,"test",prop); // PrintJob job = getToolkit().getPrintJob(this,"test",prop); if(job != null){ Graphics pg = job.getGraphics() ; if ( pg != null ){ pg.translate((job.getPageDimension().width-getSize().width)/2, (job.getPageDimension().height-getSize().height)/2); //old code - container.print(pg); print(pg); pg.dispose() ; job.end(); } } job=null; } } public FF(int x,int y){ this.setDefaultCloseOperation(3); this.setSize(x,y);//最好用变量伟值 } public void d(JPanel jp){ this.jp=jp; this.add(jp); this.setVisible(true);//必须设置为可见,估计JAVA打印时只能捕捉到屏幕上处在开启状态的程序 print(this); } public void print(JFrame frame){ Container container=frame.getContentPane(); Properties prop=new Properties(); PrintJob job = getToolkit().getPrintJob(frame,"test",prop); // PrintJob job = getToolkit().getPrintJob(this,"test",prop); if(job != null){ Graphics pg = job.getGraphics() ; if ( pg != null ){ pg.translate((job.getPageDimension().width-getSize().width)/2, (job.getPageDimension().height-getSize().height)/2); //old code - container.print(pg); print(pg); pg.dispose() ; job.end(); } } job=null; } }
用户评论