Я нашел решение / обходной путь для изменения значка диалогового окна печати Java ( не собственный).
То есть это работает для диалогового окна печати, представленного, например, sun.print.ServiceDialog
.
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());
Играйте со значениями delay
и maxCount
в соответствии с вашими потребностями. Конечно, всегда есть куда развиваться.
Очевидно, что Timer
должен быть запущен перед любым вызовом printDialog
. Например, это также работает, если таймер запускается перед вызовом JTable.print()
, когда showPrintDialog
равен true
.
Я рад, что у меня есть решение для вопроса без ответа в течение многих лет :) (по крайней мере, в моем проекте).