Example usage for java.awt.font ImageGraphicAttribute ImageGraphicAttribute

List of usage examples for java.awt.font ImageGraphicAttribute ImageGraphicAttribute

Introduction

In this page you can find the example usage for java.awt.font ImageGraphicAttribute ImageGraphicAttribute.

Prototype

public ImageGraphicAttribute(Image image, int alignment) 

Source Link

Document

Constructs an ImageGraphicAttribute from the specified Image .

Usage

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Font serifFont = new Font("Serif", Font.PLAIN, 32);

    AttributedString as = new AttributedString("www.java2s.com");
    as.addAttribute(TextAttribute.FONT, serifFont);

    Image image = createImage();/*from  ww  w.java  2 s.  com*/
    ImageGraphicAttribute imageAttribute = new ImageGraphicAttribute(image, GraphicAttribute.TOP_ALIGNMENT);
    as.addAttribute(TextAttribute.CHAR_REPLACEMENT, imageAttribute, 5, 6);

    g2.drawString(as.getIterator(), 20, 120);

}