Example usage for java.awt.font GraphicAttribute TOP_ALIGNMENT

List of usage examples for java.awt.font GraphicAttribute TOP_ALIGNMENT

Introduction

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

Prototype

int TOP_ALIGNMENT

To view the source code for java.awt.font GraphicAttribute TOP_ALIGNMENT.

Click Source Link

Document

Aligns top of graphic to top of line.

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();//  w w  w .  ja va 2s  .  c om
    ImageGraphicAttribute imageAttribute = new ImageGraphicAttribute(image, GraphicAttribute.TOP_ALIGNMENT);
    as.addAttribute(TextAttribute.CHAR_REPLACEMENT, imageAttribute, 5, 6);

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

}

From source file:AttributesApp.java

public AttributesApp() {
    setBackground(Color.lightGray);
    setSize(500, 200);//from w  ww.ja  v a 2s. com

    attribString = new AttributedString(text);

    GeneralPath star = new GeneralPath();
    star.moveTo(0, 0);
    star.lineTo(10, 30);
    star.lineTo(-10, 10);
    star.lineTo(10, 10);
    star.lineTo(-10, 30);
    star.closePath();
    GraphicAttribute starShapeAttr = new ShapeGraphicAttribute(star, GraphicAttribute.TOP_ALIGNMENT, false);
    attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, starShapeAttr, 0, 1);
    attribString.addAttribute(TextAttribute.FOREGROUND, new Color(255, 255, 0), 0, 1);

    int index = text.indexOf("Java Source");
    attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index, index + 7);
    Font font = new Font("sanserif", Font.ITALIC, 40);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 7);

    loadImage();
    BufferedImage bimage = new BufferedImage(image.getWidth(this), image.getHeight(this),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bimage.createGraphics();
    big.drawImage(image, null, this);
    GraphicAttribute javaImageAttr = new ImageGraphicAttribute(bimage, GraphicAttribute.TOP_ALIGNMENT, 0, 0);

    index = text.indexOf("Java");
    attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, javaImageAttr, index - 1, index);

    font = new Font("serif", Font.BOLD, 60);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 4);
    attribString.addAttribute(TextAttribute.FOREGROUND, new Color(243, 63, 163), index, index + 4); // Start and end indexes.

    index = text.indexOf("source");
    attribString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, index, index + 2);

    index = text.indexOf("and support");
    font = new Font("sanserif", Font.ITALIC, 40);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 10);

    attribString.addAttribute(TextAttribute.FOREGROUND, Color.white, index, index + 2); // Start and end indexes.
    attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index + 3, index + 10); // Start and end indexes.
}