Setting the top-left icon of a JDialog

You can’t directly set the top-left icon of a JDialog. It inherits its icon from the owner JFrame. What you could do is pass a dummy JFrame as the owner when you create the JDialog. This example shows you:

import javax.swing.event.*; 
import java.awt.event.*; 
import javax.swing.*; 
import java.awt.*; 
 
public class Main extends JFrame 
{ 
   private AboutBox about; 
   
   public Main() { 
      super("Main test"); 
 
      setSize(450, 350); 
 
      ImageIcon icon = new ImageIcon("first.gif"); 
      setIconImage(icon.getImage()); 
    
      JButton button = new JButton("Open dialog");
      getContentPane().setLayout(new FlowLayout());
      getContentPane().add(button);
      button.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
            about = new AboutBox(new JFrame()); 
            about.setVisible(true);
         }
      });
 
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent we) {
            System.exit(0);
         }
      });
   } 
 
   public static void main(String []args) {
      Main main = new Main();
      main.setVisible(true);
   }
}
 
class AboutBox extends JDialog 
{ 
   public AboutBox(JFrame owner) { 
      super(owner, "About Swing Menu", true); 
   
      ImageIcon icon = new ImageIcon("second.gif"); 
      owner.setIconImage(icon.getImage()); 

      JButton button = new JButton("Close");
      getContentPane().setLayout(new FlowLayout());
      getContentPane().add(button);
      button.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent ae) {
            dispose();
         }
      });
 
      setSize(250, 150); 
   }
}