All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.xhtmlrenderer.demo.browser.actions.PrintAction Maven / Gradle / Ivy

There is a newer version: 9.11.2
Show newest version
package org.xhtmlrenderer.demo.browser.actions;

import org.xhtmlrenderer.demo.browser.BrowserStartup;
import org.xhtmlrenderer.simple.XHTMLPrintable;
import org.xhtmlrenderer.util.Uu;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;

public class PrintAction extends AbstractAction {
    private final BrowserStartup root;

    public PrintAction(BrowserStartup root, ImageIcon icon) {
        super("Print", icon);
        this.root = root;
    }

    public void actionPerformed(ActionEvent evt) {
        final PrinterJob printJob = PrinterJob.getPrinterJob();
        printJob.setPrintable(new XHTMLPrintable(root.panel.view));

        if (printJob.printDialog()) {
            new Thread(() -> {
                try {
                    printJob.print();
                } catch (PrinterException ex) {
                    Uu.p(ex);
                }
            }).start();
        }

    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy