JavaFX 2窗口图标不起作用 [英] JavaFX 2 Window Icon not working

查看:952
本文介绍了JavaFX 2窗口图标不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的JavaFX 2应用程序中添加一个Icon,但我找到的方法似乎不起作用。

I'm trying to add an Icon to my JavaFX 2 application, but the ways I have found don't seem to work.

Image icon = new Image(getClass().getResourceAsStream("/images/icon.png"));
stage.getIcons().add(icon);

图标大小为32x32。

The icon is 32x32 in size.

当我尝试时

Image icon = new Image("http://goo.gl/kYEQl");

它在Netbeans和runnable jar中都有效。

It does work, in Netbeans and in the runnable jar.

我希望这可以解决。

推荐答案

问题在于图标本身。它确实像它应该加载它,但由于某种原因,它没有显示它应该显示。

The problem was in the icon itself. It did load it like it should, but for some reason it didn't display like it should.

我重新制作了我试图用于不同尺寸的图标(16x16高达512x512)并将它们全部添加到图标列表中。

I remade the icon I was trying to use to different sizes (16x16 up to 512x512) and added them all to the icon list.

stage.getIcons().add(new Image(getClass().getResourceAsStream("/images/logo_16.png")));
stage.getIcons().add(new Image(getClass().getResourceAsStream("/images/logo_32.png")));
stage.getIcons().add(new Image(getClass().getResourceAsStream("/images/logo_64.png")));
stage.getIcons().add(new Image(getClass().getResourceAsStream("/images/logo_128.png")));
stage.getIcons().add(new Image(getClass().getResourceAsStream("/images/logo_256.png")));
stage.getIcons().add(new Image(getClass().getResourceAsStream("/images/logo_512.png")));

现在它使用了应该的图标。

Now it uses the icon like it should.

这篇关于JavaFX 2窗口图标不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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