by Dinesh Thakur Category: Java 2D Example

The variable map is which allows you to assign design attributes of the object type source AttributedString. Through this variable may change any aspect of the font . TextAttribute example shown the code as follows:

import java.applet.Applet;

import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.*;
import java.awt.image.*;
import java.awt.Shape;
import java.awt.font.*;
import java.text.*;
import javax.swing.*;
public class DrawTextAttributeExample extends Applet {
public static void main(String[] args) {
Frame DrawTextAttribute  = new Frame("Draw TextAttribute  Example");
DrawTextAttribute .setSize(350, 250);
Applet DrawTextAttributeExample = new DrawTextAttributeExample();
DrawTextAttribute .add(DrawTextAttributeExample);
DrawTextAttribute .setVisible(true);
DrawTextAttribute .addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
  public void paint(Graphics g) {
    g.setFont(new Font("Arial",Font.BOLD,14));
    g.drawString("TextAttribute in Java Example", 50, 40);
    g.setFont(new Font("Arial",Font.BOLD,10));
    g.drawString("", 200, 205);
                Graphics2D G2D = (Graphics2D)g;
                String str = "Dinesh Thakur";
                AttributedString AttributedStr = new AttributedString (str);
                Font font = new Font("Arial", Font.ITALIC, 15);
                Image image = (new ImageIcon("DineshThakur.jpg")).getImage();
                ImageGraphicAttribute ImageGA = new ImageGraphicAttribute (image,(int)CENTER_ALIGNMENT);
                font = new Font("Times", Font.ITALIC, 24);
                AttributedCharacterIterator AttributedCI = AttributedStr.getIterator();
                FontRenderContext FontRC = G2D.getFontRenderContext();
               TextLayout TextLay = new TextLayout(AttributedCI,FontRC);
               TextLay.draw(G2D, 80, 70);

TextAttribute Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.