List of usage examples for javax.swing JTextPane print
public boolean print() throws PrinterException
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); }