I found a solution / workaround to change the Java print dialog box icon ( not ).
That is, this works for the print dialog presented by sun.print.ServiceDialog
, for example.
public static void changePrintDialogIcon(final Image icon) { int delay = 10; final int maxCount = 100; final Container callerRoot = FocusManager.getCurrentManager().getCurrentFocusCycleRoot(); final Timer timer = new Timer(delay, null); timer.addActionListener(new ActionListener() { private int n = 0; @Override public void actionPerformed(ActionEvent e) { Container currentRoot = FocusManager.getCurrentManager().getCurrentFocusCycleRoot(); if (callerRoot != currentRoot && currentRoot instanceof JDialog) { JDialog serviceDialog = (JDialog) currentRoot; serviceDialog.setIconImage(icon); timer.stop(); } else if (n >= maxCount) timer.stop(); } }); timer.start(); } Image icon = ...; changePrintDialogIcon(icon); PrinterJob pj = PrinterJob.getPrinterJob(); pj.printDialog(new HashPrintRequestAttributeSet());
Play with the delay
and maxCount
to suit your needs. Of course, there is always room for improvement.
Obviously, Timer
must be started before any call to printDialog
. For example, this also works if the timer starts before calling JTable.print()
when showPrintDialog
is true
.
I am glad that I have a solution for an unanswered question for many years :) (at least in my project).
IvanRF
source share