【发布时间】:2013-06-27 08:35:30
【问题描述】:
我一直在到处寻找如何在 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 评论。阅读here。它应该可以帮助您解决 jar 中嵌入资源的大多数问题。