Example usage for javax.swing JEditorPane setSize

List of usage examples for javax.swing JEditorPane setSize

Introduction

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

Prototype

public void setSize(int width, int height) 

Source Link

Document

Resizes this component so that it has width width and height height .

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);
    jep.print(graphics);// w w  w  .  j a  v a2s  .  c  o m

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

From source file:com.rapidminer.gui.flow.processrendering.annotations.AnnotationDrawUtils.java

/**
 * Calculates the preferred height of an editor pane with the given fixed width for the
 * specified string./*from www.j  a v  a2  s  . c o  m*/
 *
 * @param comment
 *            the annotation comment string
 * @param width
 *            the width of the content
 * @return the preferred height given the comment
 */
public static int getContentHeight(final String comment, final int width) {
    if (comment == null) {
        throw new IllegalArgumentException("comment must not be null!");
    }
    JEditorPane dummyEditorPane = new JEditorPane("text/html", "");
    dummyEditorPane.setText(comment);
    dummyEditorPane.setBorder(null);
    dummyEditorPane.setSize(width, Short.MAX_VALUE);

    // height is not exact. Multiply by magic number to get a more fitting value...
    if (SystemInfoUtilities.getOperatingSystem() == OperatingSystem.OSX
            || SystemInfoUtilities.getOperatingSystem() == OperatingSystem.UNIX
            || SystemInfoUtilities.getOperatingSystem() == OperatingSystem.SOLARIS) {
        return (int) (dummyEditorPane.getPreferredSize().getHeight() * 1.05f);
    } else {
        return (int) dummyEditorPane.getPreferredSize().getHeight();
    }
}