Example usage for javax.swing JEditorPane print

List of usage examples for javax.swing JEditorPane print

Introduction

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

Prototype

public void print(Graphics g) 

Source Link

Document

Invoke this method to print the component to the specified Graphics.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    String html = "<h1>Hello, world.</h1>";
    int width = 200, height = 100;

    BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration().createCompatibleImage(width, height);

    Graphics graphics = image.createGraphics();

    JEditorPane jep = new JEditorPane("text/html", html);
    jep.setSize(width, height);/*from  w  ww .j  a v  a  2  s  .  c om*/
    jep.print(graphics);

    ImageIO.write(image, "png", new File("Image.png"));
}