Problem with setIconImage
Ok so i have this code in my source
Image icon = getImage("am.ico");
mainFrame.setIconImage(icon);
But when i try to compile i get this error
cannot find symbol method getImage(java.lang.String)
I tried putting import java.lang.String
But i still get the same error.
What do i need to do for this to work?
> Would trying something like:
> > ImageIcon icon = new ImageIcon("am.ico");
>
>
>
> work?
Well i now have this
ImageIcon icon = new ImageIcon("am.ico");
mainFrame.setIconImage(icon);
But now i get this
cannot find symbol method setIconImage(javax.swing.ImageIcon)
Oh and thanx for the replies
The JFrame method setIconImage() requires an Image argument, not an Icon. (An ImageIcon is an Icon, it is not an Image).
Try using the ImageIO.read() to get a BufferedImage - it accepts both a File or a URL as an argument. Then use this BufferedImage as the argument to setIconImage().
Thanx to all who posted but i fixed it with this
Image icon = Toolkit.getDefaultToolkit().getImage("am.png");
mainFrame.setIconImage(icon);