Drawing italic/bold text in Swing

You can call the method setFont on the graphics context, or if you want to associate the font with the String, you can use the AttributedString class.

Main.java:

import java.awt.event.*;
import java.awt.font.*;
import javax.swing.*;
import java.text.*;
import java.awt.*;
 
public class Main extends JFrame {
   private boolean antiAliasing = false;
 
   public Main() {
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(1);
         }
      }); 
   }
  
   public void paint(Graphics g) {
      Graphics2D g2d = (Graphics2D) g;
       
      g2d.setFont(new Font("Helvetica", Font.PLAIN, 24));
      g2d.drawString("Gyros (setFont)", 10, 70);
 
      g2d.setFont(new Font("Helvetica", Font.BOLD, 24));
      g2d.drawString("Gyros (setFont)", 10, 100);
 
      g2d.setFont(new Font("Helvetica", Font.ITALIC, 24));
      g2d.drawString("Gyros (setFont)", 10, 130);
 
      AttributedString as = new AttributedString("Gyros (AttributedString)");
      as.addAttribute(TextAttribute.FONT, new Font("Helvetica", Font.PLAIN, 24));
      g2d.drawString(as.getIterator(), 10, 170);
 
      as = new AttributedString("Gyros (AttributedString)");
      as.addAttribute(TextAttribute.FONT, new Font("Helvetica", Font.BOLD, 24));
      g2d.drawString(as.getIterator(), 10, 200);
 
      as = new AttributedString("Gyros (AttributedString)");
      as.addAttribute(TextAttribute.FONT, new Font("Helvetica", Font.ITALIC, 24));
      g2d.drawString(as.getIterator(), 10, 230);
   }
 
   public static void main(String []args) {
      Main main = new Main();
      main.setSize(300, 250);
      main.setVisible(true);
   }
}