JTextPane打印没有打印对话框显示

时间:2016-06-25 02:58:14

标签: java swing printing

我想直接将JTextPane打印到打印机而不显示打印对话框并在屏幕上打印进度。为此,我在javadoc中找到了以下方法:

textPane.print(headerFormat, footerFormat, boolean showPrintDialog, 
     PrintService service, PrintRequestAttributeSet attributes, boolean interactive);

我不明白参数4和5.我应该为PrintServicePrintRequestAttributeSet传递哪些参数值?

请指导我如何使用此方法。

1 个答案:

答案 0 :(得分:1)

作为@Hovercraft suggests,相关的API是您的朋友。参数如下:

headerFormat - the text, in MessageFormat, to be used as the header, or null for no header
footerFormat - the text, in MessageFormat, to be used as the footer, or null for no footer
showPrintDialog - true to display a print dialog, false otherwise
service - initial PrintService, or null for the default
attributes - the job attributes to be applied to the print job, or null for none
interactive - whether to print in an interactive mode

你可以从这样的东西开始来获得默认/无行为:

textPane.print(null, null, false, null, null, false);