Results 1 to 3 of 3

Thread: setIcon

  1. #1
    pgag45 is offline Member
    Join Date
    Apr 2009
    Posts
    5
    Rep Power
    0

    Default setIcon

    Hey all,

    Read a couple forums posts on setting the application icon... (ie replacing the java icon)...

    I'm using the code, but its just not working... I have the worldicon.png in the same package this code is running in. Does it need to be in resources or am I using the wrong call?

    Thanks!

    Java Code:
            mainScreen = new MainScreen(mainScreenDriver);
            mainScreen.setIconImage(new ImageIcon("worldicon.png").getImage());
            mainScreen.setVisible(true);

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Do you know for a fact that you're looking in the right place for the "worldicon.png" file? If I didn't know, I'd create the image icon in a separate step and test if it's null or not. You know of course that java is looking at the System.getProperty("user.dir") location for your file.

    for instance place this line in your code to see just where Java is looking for the png file:
    Java Code:
    System.out.println(System.getProperty("user.dir"));
    Also, if there's any chance that you'll want to make a JAR out of this, use resources, not files. And of course resources will start looking at a different location from the user.dir, but rather will look at the location of your class files.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default

    Also, it's rather silly to construct an ImageIcon just to retrieve its Image. Use ImageIO#read (or Toolkit#createImage)

    db

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •