开发者

How to set an icon for a frame in Java?

开发者 https://www.devze.com 2022-12-21 23:22 出处:网络
I have used this statement to set icon of a frame: fra开发者_如何学JAVAme.setIconImage(Toolkit.getDefaultToolkit().getImage(\"tictactoe.gif\"));

I have used this statement to set icon of a frame:

fra开发者_如何学JAVAme.setIconImage(Toolkit.getDefaultToolkit().getImage("tictactoe.gif"));

Unfortunately the frame icon still shows default java icon instead.

How to fix this?


Check if Toolkit.getDefaultToolkit().getImage("tictactoe.gif") really reads the image. Try to split into 2 lines:

Image img = Toolkit.getDefaultToolkit().getImage("tictactoe.gif");
frame.setIconImage (img);

Then use debugger to check what is there inside img variable.


Try with ImageIcon and let us now if it works:-). It has a simple constructor taking a path to file with icon image. After construction you can retrieve image from it by calling ImageIcon.getImage().

Maybe the image is not in the right place and cannot be found?

0

精彩评论

暂无评论...
验证码 换一张
取 消