javax.print.attribute.standard.DialogTypeSelection Java Examples

The following examples show how to use javax.print.attribute.standard.DialogTypeSelection. 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: PageDlgApp.java    From TencentKona-8 with GNU General Public License v2.0 7 votes vote down vote up
public static void main(String[] args) throws Exception {

        String[] instructions =
         {
             "Visual inspection of the dialog is needed. ",
             "It should be a Printer Job Setup Dialog",
             "Do nothing except Cancel",
             "You must NOT press OK",
         };
        SwingUtilities.invokeAndWait(() -> {
            JOptionPane.showMessageDialog(
                    (Component) null,
                    instructions,
                    "information", JOptionPane.INFORMATION_MESSAGE);
        });
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
        pSet.add(DialogTypeSelection.NATIVE);
        if ((pj.pageDialog(pSet)) != null) {
            throw
            new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
                        + " does not return null when dialog is cancelled");
        }
    }
 
Example #2
Source File: PageDlgApp.java    From openjdk-jdk8u with GNU General Public License v2.0 7 votes vote down vote up
public static void main(String[] args) throws Exception {

        String[] instructions =
         {
             "Visual inspection of the dialog is needed. ",
             "It should be a Printer Job Setup Dialog",
             "Do nothing except Cancel",
             "You must NOT press OK",
         };
        SwingUtilities.invokeAndWait(() -> {
            JOptionPane.showMessageDialog(
                    (Component) null,
                    instructions,
                    "information", JOptionPane.INFORMATION_MESSAGE);
        });
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
        pSet.add(DialogTypeSelection.NATIVE);
        if ((pj.pageDialog(pSet)) != null) {
            throw
            new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
                        + " does not return null when dialog is cancelled");
        }
    }
 
Example #3
Source File: PageDlgApp.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        String[] instructions =
         {
             "Visual inspection of the dialog is needed. ",
             "It should be a Printer Job Setup Dialog",
             "Do nothing except Cancel",
             "You must NOT press OK",
         };
        SwingUtilities.invokeAndWait(() -> {
            JOptionPane.showMessageDialog(
                    (Component) null,
                    instructions,
                    "information", JOptionPane.INFORMATION_MESSAGE);
        });
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
        pSet.add(DialogTypeSelection.NATIVE);
        if ((pj.pageDialog(pSet)) != null) {
            throw
            new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
                        + " does not return null when dialog is cancelled");
        }
    }
 
Example #4
Source File: PrintAttributeUpdateTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example #5
Source File: PageDlgApp.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        String[] instructions =
         {
             "Visual inspection of the dialog is needed. ",
             "It should be a Printer Job Setup Dialog",
             "Do nothing except Cancel",
             "You must NOT press OK",
         };
        SwingUtilities.invokeAndWait(() -> {
            JOptionPane.showMessageDialog(
                    (Component) null,
                    instructions,
                    "information", JOptionPane.INFORMATION_MESSAGE);
        });
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
        pSet.add(DialogTypeSelection.NATIVE);
        if ((pj.pageDialog(pSet)) != null) {
            throw
            new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
                        + " does not return null when dialog is cancelled");
        }
    }
 
Example #6
Source File: PrintAttributeUpdateTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example #7
Source File: PageDlgApp.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        String[] instructions =
         {
             "Visual inspection of the dialog is needed. ",
             "It should be a Printer Job Setup Dialog",
             "Do nothing except Cancel",
             "You must NOT press OK",
         };
        SwingUtilities.invokeAndWait(() -> {
            JOptionPane.showMessageDialog(
                    (Component) null,
                    instructions,
                    "information", JOptionPane.INFORMATION_MESSAGE);
        });
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
        pSet.add(DialogTypeSelection.NATIVE);
        if ((pj.pageDialog(pSet)) != null) {
            throw
            new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
                        + " does not return null when dialog is cancelled");
        }
    }
 
Example #8
Source File: PrintAttributeUpdateTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example #9
Source File: PrintAttributeUpdateTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example #10
Source File: PrintAttributeUpdateTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example #11
Source File: PageDlgApp.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        String[] instructions =
         {
             "Visual inspection of the dialog is needed. ",
             "It should be a Printer Job Setup Dialog",
             "Do nothing except Cancel",
             "You must NOT press OK",
         };
        SwingUtilities.invokeAndWait(() -> {
            JOptionPane.showMessageDialog(
                    (Component) null,
                    instructions,
                    "information", JOptionPane.INFORMATION_MESSAGE);
        });
        PrinterJob pj = PrinterJob.getPrinterJob();
        PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
        pSet.add(DialogTypeSelection.NATIVE);
        if ((pj.pageDialog(pSet)) != null) {
            throw
            new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)"
                        + " does not return null when dialog is cancelled");
        }
    }
 
Example #12
Source File: PrintAttributeUpdateTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example #13
Source File: DlgAttrsBug.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job.getPrintService() == null) {
        System.out.println("No printers. Test cannot continue");
        return;
    }
    job.setPrintable(new DlgAttrsBug());
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(5));
    aset.add(new PageRanges(3,4));
    aset.add(DialogTypeSelection.NATIVE);
    job.printDialog(aset);
}
 
Example #14
Source File: PageDlgStackOverflowTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job == null) {
        return;
    }
    PrintRequestAttributeSet pSet =
         new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.NATIVE);
    job.printDialog(pSet);
    try {
        job.pageDialog(pSet);
    } catch (StackOverflowError e) {
        throw new RuntimeException("StackOverflowError is thrown");
    }
}
 
Example #15
Source File: PageDlgStackOverflowTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job == null) {
        return;
    }
    PrintRequestAttributeSet pSet =
         new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.NATIVE);
    job.printDialog(pSet);
    try {
        job.pageDialog(pSet);
    } catch (StackOverflowError e) {
        throw new RuntimeException("StackOverflowError is thrown");
    }
}
 
Example #16
Source File: ImageableAreaTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(
            0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}")
    );

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
 
Example #17
Source File: PrintDlgPageable.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    PrinterJob pj = PrinterJob.getPrinterJob();
    PageableHandler handler = new PageableHandler();
    pj.setPageable(handler);

    PrintRequestAttributeSet pSet =  new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.COMMON);
    pj.printDialog(pSet);
}
 
Example #18
Source File: DlgAttrsBug.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job.getPrintService() == null) {
        System.out.println("No printers. Test cannot continue");
        return;
    }
    job.setPrintable(new DlgAttrsBug());
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(5));
    aset.add(new PageRanges(3,4));
    aset.add(DialogTypeSelection.NATIVE);
    job.printDialog(aset);
}
 
Example #19
Source File: ImageableAreaTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(
            0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}")
    );

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
 
Example #20
Source File: ImageableAreaTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(
            0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}")
    );

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
 
Example #21
Source File: ImageableAreaTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(
            0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}")
    );

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
 
Example #22
Source File: ImageableAreaTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(
            0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}")
    );

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
 
Example #23
Source File: DlgAttrsBug.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job.getPrintService() == null) {
        System.out.println("No printers. Test cannot continue");
        return;
    }
    job.setPrintable(new DlgAttrsBug());
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(5));
    aset.add(new PageRanges(3,4));
    aset.add(DialogTypeSelection.NATIVE);
    job.printDialog(aset);
}
 
Example #24
Source File: PageDlgStackOverflowTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job == null) {
        return;
    }
    PrintRequestAttributeSet pSet =
         new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.NATIVE);
    job.printDialog(pSet);
    try {
        job.pageDialog(pSet);
    } catch (StackOverflowError e) {
        throw new RuntimeException("StackOverflowError is thrown");
    }
}
 
Example #25
Source File: ImageableAreaTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(
            0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}")
    );

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
 
Example #26
Source File: PageDlgStackOverflowTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job == null) {
        return;
    }
    PrintRequestAttributeSet pSet =
         new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.NATIVE);
    job.printDialog(pSet);
    try {
        job.pageDialog(pSet);
    } catch (StackOverflowError e) {
        throw new RuntimeException("StackOverflowError is thrown");
    }
}
 
Example #27
Source File: DlgAttrsBug.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job.getPrintService() == null) {
        System.out.println("No printers. Test cannot continue");
        return;
    }
    job.setPrintable(new DlgAttrsBug());
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(5));
    aset.add(new PageRanges(3,4));
    aset.add(DialogTypeSelection.NATIVE);
    job.printDialog(aset);
}
 
Example #28
Source File: ImageableAreaTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(
            0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}")
    );

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
 
Example #29
Source File: ImageableAreaTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(
            0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(
            JTable.PrintMode.NORMAL,
            new MessageFormat("Author Table"),
            new MessageFormat("Page - {0}")
    );

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);

    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
 
Example #30
Source File: DlgAttrsBug.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void printTest() {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job.getPrintService() == null) {
        System.out.println("No printers. Test cannot continue");
        return;
    }
    job.setPrintable(new DlgAttrsBug());
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(5));
    aset.add(new PageRanges(3,4));
    aset.add(DialogTypeSelection.NATIVE);
    job.printDialog(aset);
}