Java Code Examples for java.awt.print.PrinterJob#lookupPrintServices()

The following examples show how to use java.awt.print.PrinterJob#lookupPrintServices() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 2
Source File: WPrinterJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 3
Source File: WPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 4
Source File: WPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 5
Source File: WPrinterJob.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 6
Source File: WPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 7
Source File: WPrinterJob.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 8
Source File: WPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 9
Source File: WPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 10
Source File: WPrinterJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 11
Source File: WPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 12
Source File: WPrinterJob.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 13
Source File: WPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 14
Source File: DummyPrintTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void thirdPartyPrintLogic(String printerName) throws Exception {
    PrinterJob printerjob = PrinterJob.getPrinterJob();
    printerjob.setCopies(2);
    printerjob.setJobName("myJobName");
    printerjob.setPrintable(new DummyPrintable());
    for (PrintService printService : PrinterJob.lookupPrintServices()) {
        System.out.println("check printer name of service " + printService);
        if (printerName.equals(printService.getName())) {
            System.out.println("correct printer service do print...");
            printerjob.setPrintService(printService);
            printerjob.print();
            break;
        }
    }
}
 
Example 15
Source File: AbstractRamusPrintable.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public PrintService getPrintService() {
    if (printService == null) {
        PrintService[] lookupPrintServices = PrinterJob
                .lookupPrintServices();
        if (lookupPrintServices.length > 0)
            printService = lookupPrintServices[0];
    }
    return printService;
}
 
Example 16
Source File: PrintManager.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private void setPrintServiceForPrinter(String printer) {
    if (printer != null && !printer.isEmpty()) {
        try {
            for (PrintService one : PrinterJob.lookupPrintServices()) {
                if (one.getName().equalsIgnoreCase(printer)) {
                    mJob.setPrintService(one);
                    break;
                }
            }
        } catch (Exception exception) {
            Log.warn(exception);
        }
    }
}
 
Example 17
Source File: SettingController.java    From webapp-hardware-bridge with MIT License 5 votes vote down vote up
private ArrayList<String> listPrinters() {
    ArrayList<String> printerList = new ArrayList<>();
    PrintService[] printServices = PrinterJob.lookupPrintServices();
    for (PrintService printService : printServices) {
        printerList.add(printService.getName());
    }
    return printerList;
}
 
Example 18
Source File: PrinterOutputStream.java    From escpos-coffee with MIT License 5 votes vote down vote up
/**
 * Get the name of all printers on the system.
 *
 * @return list of printers names.
 */
public static String[] getListPrintServicesNames() {
    PrintService[] printServices = PrinterJob.lookupPrintServices();
    String[] printServicesNames = new String[printServices.length];
    for (int i = 0; i < printServices.length; i++) {
        printServicesNames[i] = printServices[i].getName();
    }
    return printServicesNames;
}