Java Reference
In-Depth Information
Directory "Sketcher 11 using the Java print dialog"
There are other HashPrintRequestAttributeSet class constructors that create non-empty attribute sets,
but this suffices for Sketcher. You need an import statement for the class in the SketcherFrame.java file:
import javax.print.attribute.HashPrintRequestAttributeSet;
Directory "Sketcher 11 using the Java print dialog"
Now that you have a print request attribute set object available, you can modify the code for printing in
the actionPerformed() method in the FileAction inner class to use the Java print dialog:
// Get a printing object
if(printer == null) { // See if there is a printer
JOptionPane.showMessageDialog(SketcherFrame.this,
"No default printer available.",
"Printer Error",
JOptionPane.ERROR_MESSAGE);
return;
}
// The view is the page source
printJob.setPrintable(theApp.getView(), pageFormat);
boolean printIt = true;
// If it's not a toolbar button
if(!(e.getSource() instanceof JButton)) {
// ...display the print dialog
printIt = printJob.printDialog(printAttr);
}
if(printIt) { // If printIt is true...
try {
printJob.print(printAttr);
// ...then print
} catch(PrinterException pe) {
System.err.println(pe);
JOptionPane.showMessageDialog(SketcherFrame.this,
"Error printing a sketch.",
"Printer Error",
JOptionPane.ERROR_MESSAGE);
}
}
Directory "Sketcher 11 using the Java print dialog"
Search WWH ::




Custom Search