如何在Swing中全局设置应用程序的图标? [英] How do I set an Application's Icon Globally in Swing?

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

问题描述

我知道我可以为每个表单指定一个表单,或者为根表单指定一个,然后它将级联到所有子表单,但是我想有一种方法可以覆盖默认的Java咖啡杯。甚至形成我可能忘记的那些。

I know I can specify one for each form, or for the root form and then it'll cascade through to all of the children forms, but I'd like to have a way of overriding the default Java Coffee Cup for all forms even those I might forget.

有什么建议吗?

推荐答案

您可以将根表单(我假设您的意思是 JFrame )作为您自己的 JFrame 的子类,然后放入其构造函数中的标准功能,例如:

You can make the root form (by which I assume you mean JFrame) be your own subclass of JFrame, and put standard functionality in its constructor, such as:

this.setIconImage(STANDARD_ICON);

您也可以在此处捆绑其他标准内容,例如将框架的窗口指标记忆为用户首选项,管理启动窗格等。

You can bundle other standard stuff in here too, such as memorizing the frame's window metrics as a user preference, managing splash panes, etc.

由此产生的任何新帧也将是此 JFrame 子类的实例。您唯一需要记住的是实例化您的子类,而不是 JFrame 。我不认为有任何替代记住这样做,但至少现在它是一个记住子类而不是 setIconImage 调用(可能还有其他功能)的问题。

Any new frames spawned by this one would also be instances of this JFrame subclass. The only thing you have to remember is to instantiate your subclass, instead of JFrame. I don't think there's any substitute for remembering to do this, but at least now it's a matter of remembering a subclass instead of a setIconImage call (among possibly other features).

这篇关于如何在Swing中全局设置应用程序的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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