Remove icon from JOptionPane

Code Hungry picture Code Hungry · Jun 7, 2013 · Viewed 12.1k times · Source

How to remove icon from JOptionPane?

ImageIcon icon = new ImageIcon(image);
JLabel label = new JLabel(icon);
int result = JOptionPane.showConfirmDialog((Component) null, label, "ScreenPreview", JOptionPane.OK_CANCEL_OPTION);

enter image description here

Answer

Dth picture Dth · Jun 7, 2013

You can do it by directly specifying the Look and Feel of your message.

Your code will take the default one, while this one will use the "PLAIN_MESSAGE" style, which lacks the icon. The behaviour of the component remains unchanged.

JOptionPane.showConfirmDialog(null, label, "ScreenPreview", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);

More info: http://docs.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html