我正在尝试打印条形码图像,但是当程序执行 .printDialog() 时,我在控制台上收到以下警告:
WARNING: gnome-keyring:: couldn't connect to: /tmp/keyring-y4THJ1/pkcs11: No such file or directory
当我点击打印按钮时,我得到空值。
这是代码:
private void jButton1MouseReleased(java.awt.event.MouseEvent evt) {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(new Printable()
{
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex != 0) {
return NO_SUCH_PAGE;
}
graphics.drawImage(imagen, 0, 0, imagen.getWidth(null), imagen.getHeight(null), null);
return PAGE_EXISTS;
}
});
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception prt) {
System.err.println(prt.getMessage());
}
}
}