java - 在 JFrame 中设置图标

标签 java swing icons jframe imageicon

我想更改项目的图标而不是java图标。当状态栏显示程序图标时,应该显示自定义图标,而不是默认的java图标。

我正在使用以下代码。请建议我这段代码有什么问题。

class newframe extends JFrame 
{

    Container cp;
    newframe()
    {
        cp=this.getContentPane();
        cp.setLayout(null);
    }

    public static void main(String args[])
    {
        newframe frm= new newframe(); 

        frm.setbounds(0,0,1000,800);
        frm.setVisible(true);
        ImageIcon im1= new ImageIcon("path upto image");
        frm.setIconImage(im1.getImage());
    }
}

最佳答案

..new ImageIcon("path upto image"); 

框架图标通常是嵌入式资源,因此必须通过 URL 访问,而不是通过 File<(表示路径的 String)访问.

关于java - 在 JFrame 中设置图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12892166/

相关文章:

java - 带有 ImageIcon 的 Eclipse 项目

java - Apache Pig - 具有多个匹配条件的 MATCHES

java - 文件存在且是目录,但 listFiles() 返回 null

java - java应用程序swing中的按钮共享图像

java - 创建可运行的 Jar 文件。 (java.lang.NoClassDefFoundError)

android - 在 TextView 中添加多个图像

swift - 在Xcode 7中不使用 Assets 目录设置应用程序图标

java - 文件名.println(String);跳过每隔一行

java - 在图像上添加按钮

android - Cordova-CLI 和图标(不包括在内)