我一直在搜索无处不在的如何在Java中设置图标图像,它总是最终不工作,或者它给了我错误。在这里,我的主要方法是我把代码:在Java中设置图标图像
public static void main(String[] args) {
Game game = new Game();
// This right here!
game.frame.setIconImage(new ImageIcon("/Icon.png").getImage());
game.frame.setResizable(false);
game.frame.setTitle(title);
game.frame.add(game);
game.frame.pack();
game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.frame.setLocationRelativeTo(null);
game.frame.setVisible(true);
}
我对图像路径为“%PROJECT%/ RES/Image.png”我只是用/Image.png先走,并访问我的res文件夹(就像我在项目的其他部分所做的那样),我甚至将它转换成了一个图标文件,并尝试过,但它决定使用默认的Java图标。
每16小时询问一次。你可能想在未来搜索。 –
+1 @AndrewThompsons评论。有一个阅读[这里](http://stackoverflow.com/questions/13796331/jar-embedded-resources-nullpointerexception/13797070#13797070)。它应该可以帮助您解决jar中嵌入资源的大多数问题。 –
请注意,我已经删除了[tag:set]标签,因为您的问题与“套件”或集合的编程概念无关。我添加了[tag:Swing]标签,因为此标题与您的问题非常相关。 –