在java中实现对FORM的打印功能

类别:Java 点击:0 评论:0 推荐:

在JAVA实现对FORM的打印功能

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

本文地址:http://com.8s8s.com/it/it18513.htm