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