JavaFX 2窗口图标不起作用

Era*_*tes 1 java icons jar executable-jar javafx-2

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

Image icon = new Image(getClass().getResourceAsStream("/images/icon.png"));
stage.getIcons().add(icon);
Run Code Online (Sandbox Code Playgroud)

图标大小为32x32.

当我尝试

Image icon = new Image("http://goo.gl/kYEQl");
Run Code Online (Sandbox Code Playgroud)

它在Netbeans和可运行的jar中都有效.

我希望这可以解决.

Era*_*tes 7

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

我将我尝试使用的图标重新制作成不同尺寸(16x16到512x512)并将它们全部添加到图标列表中.

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")));
Run Code Online (Sandbox Code Playgroud)

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