Java(本机)打印对话框 - 更改图标
我使用 PrinterJob.printDialog() 让用户选择打印机并更改各种打印设置。
然而,该对话框始终使用标准 Java 咖啡杯图标显示,而不是我的主窗口 (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的该对话框的父窗口
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我还没有找到更改图标的方法,但这是一种删除它的间接方法。
您需要通过打印属性指定 DialogOwner。这会导致 java.awt.Window 不使用默认的 Java 图标。
希望这对你现在有帮助!
当我继续寻找某种方法来定位此打印对话框时。 :)
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.
Hope this helps you for now!!
While I continue to search for some way to position this print dialog. :)
看起来 a_horse_with_no_name 会被困在没有自定义图标的打印对话框中(就像我们其他人一样)。 :-)
甚至 iReport 的打印对话框也会显示标准的咖啡杯图标。打印对话框的行为与 JFileChooser 或 JColorChooser 不同。幸运的是它是模态的。
如果图标让您太烦恼,您可以围绕它创建一个包装类,并按照您喜欢的方式处理细节。
Java6 API 不提供修改图标的方法。我会忍受咖啡杯一段时间,并等待 JDK 的下一个版本可能会提供像 JFileChooser 这样的行为。
It seems that a_horse_with_no_name will be stuck (like the rest of us) with a print dialog with no custom icon. :-)
Even iReport's print dialog appears with the standard coffee-cup icon. Print dialog does not behave like JFileChooser or JColorChooser. Fortunately it is modal.
If the icon bothers you too much, you could create a wrapper class around it, and work out the details the way you like.
Java6 API offers no way of modifying the icon. I will live with the coffee-cup for a while and will wait for the next version of the JDK that may offer a behaviour like JFileChooser.
我找到了一个解决方案/解决方法来更改 Java 打印对话框的图标(非本机)。
也就是说,这适用于例如由
sun.print.ServiceDialog
表示的打印对话框。根据您的需要使用
delay
和maxCount
值。当然,总是有改进的空间。显然,
Timer
必须在调用printDialog
之前启动。例如,如果在showPrintDialog
为true
时调用JTable.print()
之前启动计时器,这也适用。我很高兴我有一个多年来悬而未决的问题的解决方案:)(至少在我的项目中)。
I've found a solution/workaround to change the icon of a Java print dialog (not native).
That is, this works for a print dialog represented by
sun.print.ServiceDialog
, for example.Play with
delay
andmaxCount
values according to your needs. Of course, there is always room for improvement.Obviously, the
Timer
must be started before any call toprintDialog
. For instance, this also works if the timer is started before callingJTable.print()
whenshowPrintDialog
istrue
.I'm glad I have a solution for an unanswered question for years :) (at least in my project).