Forum Stats

  • 3,874,295 Users
  • 2,266,718 Discussions
  • 7,911,804 Comments

Discussions

JFrame and Taskbar icon

843810
843810 Member Posts: 46,938
edited Mar 2, 2010 11:48PM in Java Desktop Applications
I am trying to change the icon of the main JFrame and of the taskbar (not system tray) . I've been reading that setting the JFrame's icon will also change the taskbars icon. However, after mulitple attempts none have changed the JFrame's icon or the taskbar. My code for each attemps follows.

Attempt 1:
Image image = new ImageIcon("Location").getImage();
mainFrame.setIconImage(image);
Attempt 2:
Image image = Toolkit.getDefaultToolkit().getImage("Location");
mainFrame.setIconImage(image);
Attempt 3:
mainFrame.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("Location")));
Ive tried doing a try and catch, printStackTrace() doesnt occur.

Am i missing something?

Thanks,
Ross

Comments

  • darrylburke
    darrylburke Member Posts: 18,007
    ImageIcon uses Toolkit to load the Image, and Toolkit#getImage doesn't block till the image is loaded. Try loading the image using ImageIO#read.

    Also, I hope you aren't really passing the String "Location" as the path to the image resource.

    db
This discussion has been closed.