向我的应用程序添加图标问题

发布于 2025-01-04 22:17:52 字数 274 浏览 6 评论 0原文

我想更改我的应用程序的图标。 system.gif 位于当前目录中。 getDefaultToolkit() 不起作用。 getToolkit() 正在工作,但另一个最小化窗口也打开了。其他组件是Swing 组件。

Toolkit theKit = jtfMainFrame.getDefaultToolkit();
Image icon = theKit.getImage("system.gif");

I want to change the icon of my application. system.gif is in current directory. getDefaultToolkit() is not working. getToolkit() is working but another minimized window is also open. Other components are Swing components.

Toolkit theKit = jtfMainFrame.getDefaultToolkit();
Image icon = theKit.getImage("system.gif");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

友欢 2025-01-11 22:17:52

获取应用程序的图标。

  1. 将其添加到 Jar 中并使用 Class.getResource("/system.gif") 获取它的 URL。文件对象通常不适用于此类“应用程序资源”。
  2. 要加载图像,请使用ImageIO.read(URL)。这是一种阻塞方法,可确保图像在继续之前完全加载。如果出现任何问题,它还会抛出信息异常。

To get an icon for an app.

  1. Add it to the Jar and use Class.getResource("/system.gif") to obtain an URL to it. File objects will generally not work for such an 'application resource'.
  2. To load the image, use ImageIO.read(URL). This is a blocking method that will ensure the image is entirely loaded before proceeding. It will also throw informative exceptions if anything goes wrong.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文