Drawing a string in a certain font in Swing

Use the method drawString that accepts the String and the x and y parameter. Be aware that the x and y coordinates refer to the baseline, so from the bottom up. If you prefer working from the top down, you can get the font ascent (from the API: the distance between the font’s baseline and the top of most alphanumerical characters) and add it to the y coordinate:

   FontMetrics fm = g2d.getFontMetrics();
   g2d.drawString("GOD'S", 20, 100+fm.getAscent());


import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.*;
public class Main extends JFrame {
   private Image image;
   public Main() {
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
   public void paint(Graphics g) {
      g.fillRect(0, 0, getSize().width, getSize().height);
      Graphics2D g2d = (Graphics2D) g;
      Font f = new Font("Courier New", Font.BOLD, 40);
      g2d.drawString("Small", 20, 60);
      g2d.drawString("and", 20, 110);
      g2d.drawString("Humble", 20, 160);  
   public static void main(String []args) {
      Main main = new Main();
      main.setSize(180, 200);