JOptionPane title bar icon

余生颓废 提交于 2019-12-20 02:49:12

问题


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:

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


回答1:


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); 


来源:https://stackoverflow.com/questions/26702624/joptionpane-title-bar-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!