【问题标题】:Is it possible to print a Swing component without Print dialog?是否可以在没有打印对话框的情况下打印 Swing 组件?
【发布时间】:2011-12-30 07:57:37
【问题描述】:

我想在没有用户干预的情况下打印一个Swing组件(Table Component),这样打印对话框就不会出现了。

这可能吗?

【问题讨论】:

  • 我想打印没有打印对话框的表格组件。是否可以?如果可能,请告诉我。请

标签: java swing printing


【解决方案1】:

我建议阅读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);   
     }

【讨论】:

    猜你喜欢
    • 2011-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    • 2014-03-22
    • 2011-05-03
    • 2015-06-30
    相关资源
    最近更新 更多