vivek
vivek

Reputation: 4919

Is it possible to print a Swing component without Print dialog?

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

Answers (1)

mKorbel
mKorbel

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

Related Questions