Java Swing How to - Install Custom icon for JOptionPane








Question

We would like to know how to install Custom icon for JOptionPane.

Answer

import java.net.URL;
//from   ww w  . j  a va 2  s.c om
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class Main {
  public static void main(String[] args) throws Exception {

    ImageIcon icon = new ImageIcon(new URL(
        "http://www.java2s.com/style/download.png"));

    UIManager.put("OptionPane.informationIcon", icon);

    JOptionPane.showMessageDialog(null, "Hello!");
  }
}