Example usage for javax.print.attribute PrintServiceAttributeSet get

List of usage examples for javax.print.attribute PrintServiceAttributeSet get

Introduction

In this page you can find the example usage for javax.print.attribute PrintServiceAttributeSet get.

Prototype

public Attribute get(Class<?> category);

Source Link

Document

Returns the attribute value which this attribute set contains in the given attribute category.

Usage

From source file:com.akman.enjoyfood.SelectPrinters.java

/**
 * This method get all the printer installed in the system. Add then into
 * JTable./*from   w  w  w  .j a va  2 s  .  c  om*/
 */
public void getPrinters() {

    model.setRowCount(0);

    DocFlavor doc_flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();

    PrintService[] service = PrintServiceLookup.lookupPrintServices(doc_flavor, attr_set);
    for (PrintService printService : service) {

        PrintServiceAttributeSet printServiceAttributes = printService.getAttributes();
        PrinterState printerState = (PrinterState) printServiceAttributes.get(PrinterState.class);

        if (printService != null) {
            Object row[] = { new Printer(printService.getName(), true), "Online" };
            model.addRow(row);
        } else {
            Object row[] = { new Printer(printService.getName(), true), "Offline" };
            model.addRow(row);
        }
    }

}