I wish to thank you in advance for taking the time to read my question, and I would greatly appreciate any comments, answers, insights, techniques and critiques that you may be able to provide.
I'm looking for a useful method for changing the desktop icon for a Java application. I've looked into this for a few days now, but am not finding an accurate result.
Before you mark this down and call it a duplicate, I have read: How do I change the default application icon in Java? to others who asked this question), but this does not address my specific problem. I know that their method utilizes a url location instead of an import, but I am trying to learn how to use this with the import(if that is, in fact, possible). When I attempt to use their method for changing by source location. Besides that, the url example doesn't seem to work for a file stored on the computer. I get an "uncaught error" message when I attempt to run it.
I use the following format to declare an image that I have imported into NetBeans:
Image image = new ImageIcon("imported.png").getImage();
frame.setIconImage(image);
Now this works fine for the icon that displays in the toolbar and it also appears in the upper left-hand corner of the frame, but I still have the Java coffee-cup as the icon for the application when I clean and build it.
For additional resources to the code that I am using to attempt this:
import java.awt.Image;
import javax.swing.*;
public class Check {
JFrame frame;
public static void main(String[] args) {
new Check().go();
}
private void go() {
frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Image image = new ImageIcon("owl.gif").getImage();
frame.setIconImage(image);
frame.setVisible(true);
frame.setSize(300, 300);
}
}
The "owl.gif" bit is what I imported into NetBeans by click and drag method (as described in one of the books that I read that focused on NetBeans).
I'm looking for a way to make a file that I already have saved on my computer the desktop icon for my application after it is built.
Image image = new ImageIcon(Check.class.getResource("/owl.gif")).getImage();
. More info can be found on this answer of mine :-) – Onshore