Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOptionPane title bar icon

I'd like to replace the icon in a JOptionPane title bar (as it currently shows the default Java coffee logo).

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 to change the icon in the title bar or alternatively to hide the default Java icon without having to implement a JDialog class?

Thanks a bunch! Thomas

like image 340
Tom Avatar asked Oct 23 '25 19:10

Tom


1 Answers

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.DEFAULT_OPTION,   
  icon);  
JDialog dialog = jp.createDialog(null, "Session Expired - Please Re Login");
((Frame)dialog.getParent()).setIconImage(((ImageIcon)icon).getImage());  
dialog.setResizable(true);  
dialog.setVisible(true); 
like image 63
Sainath S.R Avatar answered Oct 26 '25 08:10

Sainath S.R