I am currently trying to generate a print method which will allow the
user to both select the orientation (portrait vs. landscape) and the
printer. The PrintDialog method allows the user to select the
printer and has a "Properties" button that you can click on and
change the orientation. However when I change any characteristics
(such as orientation) found under the "Properties" button it doesn't
save those changes into the print job. I always get the default
(portrait). I tried using the PageDialog option (which appears to
work wonderfully, but I am unable to determine if the user hits
the "cancel" or the "OK" button. Cancel (I am told from the
documentation) return the default characteristics; but this could be
a valid response if the user doesn't change any printer settings.
The only way to get my page orientation and the cancel button to work
at the same time (it seems anyway) is to use both the PageDialog and
PrintDialog methods. But this means having two windows pop up
everytime to allow printing (and if the user uses the "properties"
button on the PrintDialog window it is still ignored).
Anyone know a way to maybe use just the PageDialog method and still
be able to allow the user to cancel. Or a way to get
the "Properties" button information to stick from the PrintDialog
method. Either that or does anyone have an example of an alternative
java example that allows the user to select the printers and
orientation using another means (I am very new to java so I need a
pretty detailed example).
Below is an example of the code using both windows. But again I hate
this two window process which still seems a little flukey:
public void printData() {
try {
PrinterJob prnJob = PrinterJob.getPrinterJob();
PageFormat pf = prnJob.pageDialog(prnJob.defaultPage());
prnJob.setPrintable(this,pf);
if (!prnJob.printDialog())
return;
setCursor( Cursor.getPredefinedCursor(
Cursor.WAIT_CURSOR));
prnJob.print();
setCursor( Cursor.getPredefinedCursor(
Cursor.DEFAULT_CURSOR));
}
catch (PrinterException e) {
e.printStackTrace();
System.err.println("Printing error: "+e.toString());
JOptionPane.showMessageDialog(this,
"Printing error: "+e.toString(), "Printer",
JOptionPane.INFORMATION_MESSAGE);
}