Java Swing How to - Remove icon from JOptionPane








Question

We would like to know how to remove icon from JOptionPane.

Answer

import java.awt.BorderLayout;
import java.awt.Image;
import java.awt.image.BufferedImage;
//from w ww .jav a 2  s . co  m
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Main {

  public static void main(String[] args) {
    Image image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    JPanel gui = new JPanel(new BorderLayout());

    JLabel clouds = new JLabel(new ImageIcon(new BufferedImage(250, 100,
        BufferedImage.TYPE_INT_RGB)));
    gui.add(clouds);

    JOptionPane.showConfirmDialog(null, gui, "Title",
        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
        new ImageIcon(image));
  }
}