Font paint : Font « 2D Graphics GUI « Java

Font paint

Font paint
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class SimpleFont extends JPanel{
    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;

        String s = "Java Source and Support";
        Font font = new Font("Serif", Font.PLAIN, 24);
        FontRenderContext frc = g2.getFontRenderContext();

        GlyphVector gv = font.createGlyphVector(frc, s);
        g2.drawGlyphVector(gv, 40, 60);

  public static void main(String[] args) {
    JFrame f = new JFrame();
    f.getContentPane().add(new SimpleFont());
    f.setSize(350, 250);;


Related examples in the same category

1.Ascii font pattern
2.A cache of the dynamically loaded fonts found in the fonts directory
3.Load font from ttf file
4.Outline Font paintOutline Font paint
5.Font DerivationFont Derivation
6.Font centeredFont centered
7.Font ListFont List
8.FontDemo lists the system fonts and provides a sample of each one(Have some problems)
9.Finds and displays available fonts
10.Obtain FontMetrics of different fonts
11.Draw font inside a Rectangle
12.Display font in a grid
13.Create font from true type font
14.Wrap string according to FontMetrics
15.Draw base line and enclosing line for a font
16.List all Fonts