JOptionPane Header Icon

I want to replace the icon in the JOptionPane title bar (as it is showing the default Java logo at the moment).

I tried the following:

JOptionPane.showMessageDialog(null, "Some Text", "Login",
 JOptionPane.INFORMATION_MESSAGE, ImageCacheProvider
   .instance.getImageIcon("img/an image.png"));

      

It replaces the icon in the window, but not the one in the title bar:

Screenshot title bar

Is there any approach for changing the icon in the title bar, or alternatively for hiding the default Java icon without having to implement the JDialog class?

Thank! Thomas

+3


source to share


1 answer


Use it like this:



Icon icon = new ImageIcon("d:/temp/CheckBox.gif");  
JOptionPane jp = new JOptionPane("Session Expired - Please Re Login"),   
  JOptionPane.INFORMATION_MESSAGE,   
  JOptionPane.WARNING_MESSAGE,   
  icon);  
JDialog dialog = jp.createDialog(null, "Session Expired - Please Re Login");
((Frame)dialog.getParent()).setIconImage(((ImageIcon)icon).getImage());  
dialog.setResizable(true);  
dialog.setVisible(true); 

      

+5


source







All Articles