我想在没有用户干扰的情况下打印Swing组件(表组件),这样打印对话框就不会显示出来。
这可能吗?
答案 0 :(得分:4)
我建议阅读Printing教程,
MessageFormat header = new MessageFormat(" Whatever");
MessageFormat footer = new MessageFormat(" Page {0,number,integer} Whatever");
try {
PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
set.add(OrientationRequested.LANDSCAPE);
myTable.print(JTable.PrintMode.FIT_WIDTH, header, footer, false, set, false);
JOptionPane.showMessageDialog(null, "\n" + "JTable was Successfully "
+ "\n" + "Printed on your Default Printer");
} catch (java.awt.print.PrinterException e) {
JOptionPane.showMessageDialog(null, "\n" + "Error from Printer Job "
+ "\n" + e);
}