'how can i hide printerjob dialog when i try to print?
i hope you're doing great. So i'm having a problem with my printing method. i used printerjob to print some papers records from my java application, and the printing dialog is showing twice everytime, after i click okey to print it shows again, and is there a way i can hide it all ? printing would start diractly after the user click ?
public void print(JPanel paneltoprint){
PrinterJob printer = PrinterJob.getPrinterJob();
printer.setJobName("print attestation");
printer.setPrintable(new Printable() {
@Override
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if(pageIndex > 0){
return Printable.NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D) graphics;
g2d.translate(pageFormat.getImageableX()*3, pageFormat.getImageableY()*3);
g2d.scale(0.7, 0.7);
paneltoprint.paint(g2d);
return Printable.PAGE_EXISTS;
}
});
boolean returnResult = printer.printDialog();
if(returnResult){
try {
printer.print();
} catch (PrinterException ex) {
Logger.getLogger(Attestation.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
