本文介绍了如何将图标设置为 JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过这种方法,但没有改变?
I tried this way, but it didnt changed?
ImageIcon icon = new ImageIcon("C:\Documents and Settings\Desktop\favicon(1).ico"); frame.setIconImage(icon.getImage()); 推荐答案最好使用 .png 文件;.ico 是特定于 Windows 的.并且最好不要使用文件,而是使用类资源(可以打包在应用程序的 jar 中).
Better use a .png file; .ico is Windows specific. And better to not use a file, but a class resource (can be packed in the jar of the application).
URL iconURL = getClass().getResource("/some/package/favicon.png"); // iconURL is null when not found ImageIcon icon = new ImageIcon(iconURL); frame.setIconImage(icon.getImage());尽管您甚至可能会考虑将 setIconImages 用于多种尺寸的图标.
Though you might even think of using setIconImages for the icon in several sizes.
更多推荐
如何将图标设置为 JFrame
发布评论