I've already tried loads of code from Stack. For some reason it's just not setting the ImageIcon for my JFrame, the comments are other attempts that have not worked;I avoided calling super so that I could reference the JFrame -- GUIPhotoAlbum extends
JFrame; code:
public GUIPhotoAlbum ()
{
super("PhotoAlbum");
ImageIcon img = new ImageIcon("Photos/albumIcon.png");
this.setIconImage(img.getImage());
/*
try{
setIconImage(ImageIO.read(new File("Photos/albumIcon.png")));
}catch(Exception e){
System.out.print("Didn't work.");
}
*/
setSize(875, 625);
this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout(5, 5));
initComponents();
initMenuBar();
initTopPanel();
add(topPanel, BorderLayout.CENTER);
initBottomPanel();
add(bottomPanel, BorderLayout.SOUTH);
addListeners();
setLocationRelativeTo(null);
setVisible(true);
}
EDIT
I'm running the program like this, where I try to set the ImageIcon of JFrame in the GUIPhotoAlbum()
constructor; here's the driver:
public class AlbumDriver
{
public static void main (String [ ] args)
{
SwingUtilities.invokeLater
(
new Runnable()
{
@Override
public void run()
{
GUIPhotoAlbum pa = new GUIPhotoAlbum();
}
}
);
}
}
What am I doing wrong here?
PS I've tried BufferedImage
, ImageIcon
, using File
.. and I'm using a Mac
Mac does not support frame icons, as seen in this answer.