Reputation: 5345
I would like to replace the java launch icon:
I am starting my application via spring and put my icon here inside:
I am starting my gui like that my MainWindow
extends a JFrame
:
/**
* starts the GUI
*/
public void start() {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
Toolkit.getDefaultToolkit().getImage(MainWindow.class.getResource("icon.png"));
makeLayout();
}
});
}
However the icon does not change. Any recommendation what I could do?
I appreciate your answer!
Upvotes: 0
Views: 101
Reputation: 12332
Toolkit.getDefaultToolkit().getImage()
returns an image, but you are not doing anything with it. You need to use setIconImage()
. Try this...
setIconImage(Toolkit.getDefaultToolkit().getImage(
MainWindow.class.getResource("icon.png")));
Upvotes: 2
Reputation: 9
I believe your path needs to include the "/resources/" part. so it would look like this:
Toolkit.getDefaultToolkit().getImage(MainWindow.class.getResource("resources/icon.png"));
Upvotes: 0
Reputation: 742
URL url = new URL(path);
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.createImage(url);
getFrame().setIconImage(img);
The URL can throw MalformedUrlException. If so happens, then just replace the first line with this
URL url = ClassLoader.getSystemResource(path);
Upvotes: 0