Center a text over a JButton’s icon

Use the JButton’s methods setHorizontalTextPosition and setVerticalTextPosition.
Main.java:

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
   
public class Main extends JFrame implements ActionListener {
   JList list; 
 
   public Main() {
      getContentPane().setLayout(new FlowLayout());
 
      JButton fbutton = new JButton("Text Over Image", new ImageIcon("female.gif"));
      fbutton.addActionListener(this);
      fbutton.setVerticalTextPosition(SwingConstants.CENTER);
      fbutton.setHorizontalTextPosition(SwingConstants.CENTER); 
 
      getContentPane().add(BorderLayout.CENTER, fbutton);
 
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent event) {
            System.exit(0);   
         }      
      });
 
      setSize(400, 400);
   }
 
   public void actionPerformed(ActionEvent ae) {
      System.out.println("Your pressed the "" + ae.getActionCommand() + "" button");
   }
   
   public static void main(String[] args) {
      (new Main()).show();
   }
}