Reputation: 4919
I would like to print a Swing component (Table Component) without user interference, so that the print dialog box doesn't show up.
Is that possible?
Upvotes: 4
Views: 1352
Reputation: 109813
I'd suggesting to read Printing tutorial,
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);
}
Upvotes: 4