Listening for Print Job Attribute Changes - Java 2D Graphics

Java examples for 2D Graphics:Print

Description

Listening for Print Job Attribute Changes

// Create the print job
DocPrintJob job = service.createPrintJob();
PrintJobAttributeSet set = new HashPrintJobAttributeSet(job.getAttributes());
set.add(new JobMediaSheetsCompleted(0));
job.addPrintJobAttributeListener(new MyPrintJobAttributeListener(), set);

class MyPrintJobAttributeListener implements PrintJobAttributeListener {
    public void attributeUpdate(PrintJobAttributeEvent pjae) {
        // Get the set of attributes that have changed
        Attribute[] attrs = pjae.getAttributes().toArray();

        for (int i=0; i<attrs.length; i++) {
            String attrName = attrs[i].getName();
            String attrValue = attrs[i].toString();
            process(pjae, attrName, attrValue);
        }
    }
}

Related Tutorials