Example usage for javax.swing JTextPane print

List of usage examples for javax.swing JTextPane print

Introduction

In this page you can find the example usage for javax.swing JTextPane print.

Prototype


public boolean print() throws PrinterException 

Source Link

Document

A convenience print method that displays a print dialog, and then prints this JTextComponent in interactive mode with no header or footer text.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame jframe = new JFrame();
    jframe.setSize(500, 200);/* www.j a va  2s  . c  om*/
    jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextPane jTextPane = new JTextPane();
    jTextPane.setEditorKit(new HTMLEditorKit());
    JButton btn = new JButton("Print");
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                jTextPane.setContentType("text/html");
                boolean done = jTextPane.print();
                if (done) {
                    System.out.println("Printing is done");
                } else {
                    System.out.println("Error while printing");
                }
            } catch (Exception pex) {
                pex.printStackTrace();
            }
        }
    });
    jframe.add(btn, BorderLayout.SOUTH);
    jframe.add(jTextPane);
    jframe.setVisible(true);
}