如何将图标设置为 JFrame

编程入门 行业动态 更新时间:2024-10-10 02:14:39
本文介绍了如何将图标设置为 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

本文发布于:2023-11-25 21:45:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631464.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:设置为   如何将   图标   JFrame

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!