Forum Stats

  • 3,874,951 Users
  • 2,266,788 Discussions
  • 7,912,025 Comments

Discussions

How to Change Icon of Desktop Application?

829396
829396 Member Posts: 4
edited Jun 2, 2011 3:43AM in Java Desktop Applications
Friends, i am developing one small software using Java Desktop Application in Netbeans. I want to change the icon of my application (cup of coffee). I have tried this code: URL url = new URL("myApplication/resourcesresources/camera.png");
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.createImage(url);
this.getFrame().setIconImage(img);

and

URL url = new URL("F:/Documents and Settings/Selva/My Documents/NetBeansProjects/HashCodeCracker/src/myApplication/resourcesresources/camera.png");
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.createImage(url);
this.getFrame().setIconImage(img);

i have searched in google and nothing works . Can anyone solve this problem?

Note:
This code works for me:
Toolkit kit = Toolkit.getDefaultToolkit();
Image frameIcon = kit.getImage("F:\\Documents and Settings\\Selva\\My Documents\\NetBeansProjects\\HashCodeCracker\\src\\hashcodecracker\\resources\\PasswordCrackerIcon.jpg");
this.getFrame().setIconImage(frameIcon);

But i am creating software. So i can not specify the location of the Image in one path. The user may run the software from anywhere. So the above code can not be used.

Thanks

Edited by: Blackstar on Jun 1, 2011 8:46 PM

Answers

  • darrylburke
    darrylburke Member Posts: 18,007
    http://download.oracle.com/javase/tutorial/uiswing/components/icon.html#getresource

    db
    darrylburke
  • User_64CKJ
    User_64CKJ Member Posts: 7,279 Silver Badge
    Blackstar wrote:
    Friends, i am developing one small software using Java Desktop Application in Netbeans. I want to change the icon of my application (cup of coffee). I have tried this code: URL url = new URL("myApplication/resourcesresources/camera.png");
    You really have a directory called <tt>resourcesresources</tt>?
    -------------------
    Please use the code tags as described in the sticky post at the top of the forum thread listing.
This discussion has been closed.