在JFrame中设置图标 [英] Set icon in JFrame

查看:466
本文介绍了在JFrame中设置图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to change the icon of the project instead of java icon. When the program icon is being displayed in status bar, it should be displaying the customized icon instead of default java icon.

我使用以下代码。请告诉我这段代码有什么问题。

I am using the following code. Please suggest me what's wrong in this code.

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 而不是(表示路径的 String 文件

A frame icon will typically be an embedded-resource, so must be accessed by URL rather than (a String representing a path to) a File.

这篇关于在JFrame中设置图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆