This shows the icon when I launch through eclipse, but when I export it to a Runnable Jar It shows the default Java icon, I do not want to use the Resource way of doing it since it doesn't work in the IDE even.
public static void main(String args[]) {
Game component = new Game();
ImageIcon img = new ImageIcon("res/game.png");
JFrame frame = new JFrame();
frame.add(component);
frame.setTitle(NAME);
frame.setIconImage(img.getImage());
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
component.start();
}
The problem was that I was using the wrong run as file, a stupid mistake but thats what I get for not having my Workspace clean.
I'd like to thank everyone who tried to help.
please use the following code
and put your icon file in
res
folder ofsrc
folder. But it'll display the icon of frame when you execute the jar file. Working fine for me.Try this following code to set the iconImage to the frame:
Even in this oracle doc you can find this same approach.
Edit: Have you tried this code. It might be helpful:
Check out this explation too.