想制作一个组合框,选项是所有该电脑可用的打印机列表,没有经验,求帮助,谢谢
java 打印机列表
------解决方案--------------------
import java.io.File;
import java.io.FileInputStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.ServiceUI;
import javax.print.SimpleDoc;
import javax.print.attribute.DocAttributeSet;
import javax.print.attribute.HashDocAttributeSet;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.swing.JFileChooser;
public class Printers
{
public static void main(String[] args)
{
HashPrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
//查找所有的可用的打印服务
PrintService[] printService = PrintServiceLookup.lookupPrintServices(flavor, pras);
for (int i =0; i<printService.length ;i++ )
{
System.out.println(printService[i].getName());
}
}
}