我一直在搜索無處不在的如何在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]標籤,因爲此標題與您的問題非常相關。 –