Remove icon from JOptionPane

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

+7
source share
2 answers

You can do this by indicating directly or indirectly your opinion.

Your code will be used by default, while this one will use the "PLAIN_MESSAGE" style, which does not have an icon. The behavior of the component remains unchanged.

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

Additional information: http://docs.oracle.com/javase/6/docs/api/javax/swing/JOptionPane.html

+19
source

It is quite simple using the transparent icon as shown below (as opposed to the black “splash screen”). Although note that although the options bar offers some “room for maneuver” in terms of how it is displayed, go on to change a few things, and instead it quickly becomes easier to use JDialog .

Icon Free Option Pane

 import java.awt.*; import java.awt.image.BufferedImage; import javax.swing.*; class IconFree { public static void main(String[] args) { Runnable r = new Runnable() { @Override public void run() { // A transparent image is invisible by default. Image image = new BufferedImage( 1, 1, BufferedImage.TYPE_INT_ARGB); JPanel gui = new JPanel(new BorderLayout()); // ..while an RGB image is black by default. 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)); } }; // Swing GUIs should be created and updated on the EDT // http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html SwingUtilities.invokeLater(r); } } 
+2
source

All Articles