Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java (native) print dialog - change icon

Tags:

java

printing

awt

I use PrinterJob.printDialog() to let the user select a printer and change various print settings.

However the dialog is always displayed using the standard Java coffeecup icon and not the one from my main window (JFrame).

How can I change the icon for that dialog?

I'm using the following piece of code:

PrinterJob pj = PrinterJob.getPrinterJob(); 
pj.printDialog(); // how do I change the icon for the dialog that is displayed here

... // process the selection from the dialog

Normally a JDialog inherits the icon from the "parent" JFrame, but in this case I cannot pass or specify a parent window for that dialog

I'm using Java6

like image 951
a_horse_with_no_name Avatar asked Feb 03 '23 23:02

a_horse_with_no_name


1 Answers

I have not found a way to change the icon, but here is one indirect way to Remove it.

You need to specify a DialogOwner via the print attributes. This causes java.awt.Window to not use the default Java icon.

PrinterJob pj = PrinterJob.getPrinterJob(); 
// Create an Attribute set
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

// A different way to bring Up Native Dialog from Java
aset.add(sun.print.DialogTypeSelection.NATIVE); 
// Looks like this class is being moved to javax.print.attribute.standard for Java 7

// To Remove the Icon from the dialog provide an owner.
Frame f = Frame();            
aset.add(new sun.print.DialogOwner(f));

pj.printDialog(aset); // The dialog should not have an icon now.

Hope this helps you for now!!

While I continue to search for some way to position this print dialog. :)

like image 116
Optimus Prime Avatar answered Feb 05 '23 16:02

Optimus Prime