Example usage for org.jfree.text TextUtilities createTextBlock

List of usage examples for org.jfree.text TextUtilities createTextBlock

Introduction

In this page you can find the example usage for org.jfree.text TextUtilities createTextBlock.

Prototype

public static TextBlock createTextBlock(final String text, final Font font, final Paint paint,
        final float maxWidth, final TextMeasurer measurer) 

Source Link

Document

Creates a new text block from the given string, breaking the text into lines so that the maxWidth value is respected.

Usage

From source file:org.jfree.demo.TextBlockPanel.java

/**
 * Paints the panel.//from w  w  w.j a  va2 s  . c o  m
 *
 * @param g  the graphics device.
 */
public void paintComponent(final Graphics g) {

    super.paintComponent(g);
    final Graphics2D g2 = (Graphics2D) g;

    final Dimension size = getSize();
    final Insets insets = getInsets();
    final Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
            size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom);

    final double x = available.getX();
    final double y = available.getY();
    final float width = (float) available.getWidth();
    final TextBlock block = TextUtilities.createTextBlock(this.text, this.font, Color.black, width,
            new G2TextMeasurer(g2));
    g2.setPaint(Color.black);
    block.draw(g2, (float) x, (float) y, TextBlockAnchor.TOP_LEFT, 0.0f, 0.0f, 0.0);

}