下面的代码显示了标准的awt/swing打印对话框。所有工作正常,但在对话框中点击按钮“属性”调用没有打印机属性对话框。
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.print.PrinterJob;
import java.util.Locale;
import javax.print.DocFlavor;
import javax.print.DocFlavor.SERVICE_FORMATTED;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.ServiceUI;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.swing.SwingUtilities;
public class PrintTryout {
public static void main(String[] args) {
Locale.setDefault(Locale.ENGLISH);
SwingUtilities.invokeLater(new PrintTryout()::startUp);
}
private void startUp() {
PrintService[] services = PrintServiceLookup.lookupPrintServices(
DocFlavor.INPUT_STREAM.JPEG, null);
PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
if (services.length > 0) {
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
ServiceUI.printDialog(gc, 50, 50,
services, services[0],
SERVICE_FORMATTED.PAGEABLE,
attributes);
}
}
private void startUp2() {
PrinterJob pj = PrinterJob.getPrinterJob();
pj.printDialog();
}
}
如果我将调用的方法更改为 startUp2
,我得到另一个打印对话框,也有“属性”按钮。这个按钮工作正常:我得到打印机设置对话框。是java错误还是我做错了什么?或者可能对某些人是正确的(我从一个客户那里得到了这个bug)?
暂无答案!
目前还没有任何答案,快来回答吧!