是否可以在没有“打印”对话框的情况下打印Swing组件?

时间:2011-12-30 07:57:37

标签: java swing printing

我想在没有用户干扰的情况下打印Swing组件(表组件),这样打印对话框就不会显示出来。

这可能吗?

1 个答案:

答案 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);   
     }