我用它PrinterJob.printDialog()来让用户选择一台打印机并更改各种打印设置.
但是,对话框始终使用标准Java coffeecup图标显示,而不是我主窗口(JFrame)中的图标.
如何更改该对话框的图标?
我正在使用以下代码:
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
通常,JDialog从"父"JFrame继承图标,但在这种情况下,我无法传递或指定该对话框的父窗口
我正在使用Java6
小智 8
我还没有找到更改图标的方法,但这是一种间接的删除方法.
您需要通过print属性指定DialogOwner.这会导致java.awt.Window不使用默认的Java图标.
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.
Run Code Online (Sandbox Code Playgroud)
希望这对你有所帮助!!
我继续寻找一些方法来定位这个打印对话框.:)
看起来 a_horse_with_no_name 会被困在没有自定义图标的打印对话框中(就像我们其他人一样)。:-)
甚至 iReport 的打印对话框也会显示标准的咖啡杯图标。打印对话框的行为与 JFileChooser 或 JColorChooser 不同。幸运的是它是模态的。
如果图标让您太烦恼,您可以围绕它创建一个包装类,并按照您喜欢的方式处理细节。
Java6 API 不提供修改图标的方法。我会忍受咖啡杯一段时间,并等待 JDK 的下一个版本可能会提供像 JFileChooser 这样的行为。