- java.lang.Object
 -  
      
- javax.print.ServiceUI
 
 
-  
       
public class ServiceUI extends Object
此类是UI便捷方法的集合,它提供了一个图形用户对话框,用于浏览通过Java Print Service API查找的打印服务。对话框遵循标准模式,充当用户的继续/取消选项,并允许用户选择要使用的打印服务并指定选项,如纸张大小和份数。
这些对话框旨在通过这些打印服务的公共API与可插拔打印服务一起使用。
如果打印服务提供任何供应商扩展,则可以通过供应商提供的选项卡面板
Component使用户可以访问这些扩展。 鼓励这样的供应商扩展使用Swing! 并支持其辅助功能API。 供应商扩展应将设置作为AttributeSet一部分返回。 想要保留用户设置的应用程序应使用这些设置来指定打印作业。 请注意,此类未被Java Print Service的任何其他部分引用,并且可能不包含在不依赖于AWT包的存在的配置文件中。 
-  
        
       
-  
             
构造方法摘要
构造方法 构造器 描述 ServiceUI() 
-  
             
方法摘要
所有方法 静态方法 具体的方法 变量和类型 方法 描述 static PrintServiceprintDialog(GraphicsConfiguration gc, int x, int y, PrintService[] services, PrintService defaultService, DocFlavor flavor, PrintRequestAttributeSet attributes)向用户显示用于选择打印服务(打印机)的对话框。 
 -  
             
 
-  
        
       
-  
             
方法详细信息
-  
printDialog
public static PrintService printDialog(GraphicsConfiguration gc, int x, int y, PrintService[] services, PrintService defaultService, DocFlavor flavor, PrintRequestAttributeSet attributes) throws HeadlessException
向用户显示用于选择打印服务(打印机)的对话框。 它显示在应用程序指定的位置,并且是模态的。 如果规范无效或者使对话框不可见,它将显示在由实现确定的位置。 该对话框阻止其调用线程,并且是应用程序模式。对话框可以包括与从所述懒惰地获得定制UI一个标签面板
PrintService的ServiceUIFactory当PrintService浏览。 该对话框将首先尝试将MAIN_UIROLE定位为JComponent,然后定位为Panel。 如果没有ServiceUIFactory或没有匹配的角色,则自定义选项卡将为空或不可见。如果用户确定对话框,则对话框返回用户选择的打印服务
null如果用户取消对话框,则null。应用程序必须传入一组打印服务才能浏览。 该数组必须为
non-null且非空。 通常,应用程序将仅PrintServices能够打印特定文档风格的PrintServices。应用程序可以传入
PrintService以进行初始显示。non-null参数必须包含在可浏览服务数组中。 如果此参数为null,则实现选择服务。应用程序可以任选地传递要打印的香料。 如果这是
non-null,则可以更好地验证向用户提供的选项与服务支持的选项。 应用程序必须传入PrintRequestAttributeSet以返回用户选择。 在调用PrintRequestAttributeSet可能为空,或者可能包含应用程序指定的值。这些用于设置最初显示的打印服务的初始设置。 打印服务不支持的值将被忽略。 当用户浏览打印服务时,属性和值将复制到新显示中。 如果用户浏览不支持特定属性值的打印服务,则该服务的默认值将用作要复制的新值。
如果用户取消对话框,则返回的属性不会反映用户所做的任何更改。
此方法的典型基本用法可能是:
PrintService[] services = PrintServiceLookup.lookupPrintServices( DocFlavor.INPUT_STREAM.JPEG, null); PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); if (services.length > 0) { PrintService service = ServiceUI.printDialog(null, 50, 50, services, services[0], null, attributes); if (service != null) { ... print ... } }- 参数
 -  
              
gc- 用于选择屏幕,null表示主屏幕或默认屏幕 -  
              
x- 对话框的位置,包括相对于gc原点的屏幕坐标中的gc -  
              
y- 对话框的位置,包括相对于gc原点的屏幕坐标中的gc -  
              
服务- 要可浏览,必须是non-null -  
              
defaultService- 要显示的初始值PrintService -  
              
flavor- 要打印的风味,或null -  
              
attributes- on input是初始应用程序提供的首选项。 这不能是null但可能是空的。 在输出时,属性反映用户所做的更改。 - 结果
 - 
               用户选择的打印服务,如果用户取消了对话框,则输入 
              
null - 异常
 -  
              
HeadlessException- 如果GraphicsEnvironment.isHeadless()返回true -  
              
IllegalArgumentException- if services isnullor empty, or attributes isnull, or the initialPrintServiceis not in the list of browsable services 
 
 -  
 
 -