发布网友 发布时间:2022-04-22 08:23
共1个回答
热心网友 时间:2022-06-18 13:30
Toolkit kit = Toolkit.getDefaultToolkit();
Properties props = new Properties();
props.put("awt.print.printer", "your printer");
props.put("awt.print.numCopies", "1");
PrintJob printJob = kit.getPrintJob(this, "打印", props); //this指你的JFrame
Graphics2D g2 = (Graphics2D)printJob.getGraphics();
PageFormat pf = new PageFormat();
g2.translate(pf.getImageableX(), pf.getImageableY());
jtable.printAll(g2);
g2.dispose();
printJob.end();
这是最简单的代码,复杂的只能自己学习了追问不理解。。。。