Results 1 to 9 of 9
  1. #1
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Question Problem in setting icon for JFrame!

    hi all,
    I want to change the icon of the JFrame. I have done this by coding. It is working fine in NetBeans IDE. But it is not displaying the icon after building jar.
    I am getting this problem when i am trying to run the jar file.

    I have tried the following codes. But they are not working after building jar.
    (I kept the image file in resources folder).
    Please go through it and suggest me possible workarounds.

    -----------
    this.setIconImage(java.awt.Toolkit.getDefaultToolk it().getImage("myicon.jpg"));
    -----------
    this.setIconImage(java.awt.Toolkit.getDefaultToolk it().getImage(Step1.class.getResource("myicon.jpg" )));
    -----------
    InputStream imgStream = this.getClass().getResourceAsStream("myicon.jpg");
    BufferedImage bi = ImageIO.read(imgStream);
    ImageIcon myImg = new ImageIcon(bi);
    this.setIconImage(myImg.getImage());
    ------------

    Thanks in advance!
    Thanks and Regards,
    Pranav

  2. #2
    etheralthougt is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default

    have you tried adding the ImageIcon to a JLabel, and then placing that into a JFrame?

    I think you can't directly add an ImageIcon to a JFrame, it needs to be in a JLabel.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I think he's talking about the image on tittle bar.

    How did you build the jar file? In that case can you granted that all resources, I mean images and stuff, are in the correct location.

  4. #4
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    i have developed this in NetBeans IDE.
    I directly builded jar from the IDE itself.
    Still, its not working.

    pls suggest me a solution for this.
    Thanks and Regards,
    Pranav

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Ok you build the jar file using NetBeans. So the jar file is contain in the dist folder. Can you run the jar file on that same location. What happen when you run.

    And also the best thing is, place all images in a separate folder. Just putting them in the project folder is not a good idea.

  6. #6
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    Sorry, for the late reply!

    i kept the images in resources. even i run the jar from same location also, i am getting the same problem(i.e., it is not displaying my icon, its just displaying the default icon).
    Thanks and Regards,
    Pranav

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    When using the getResource method, how are you adding the image file to the jar file? It should not have a path in the jar file.
    Can you look in the jar file and see that it does not have a path?

  9. #9
    pranav13's Avatar
    pranav13 is offline Member
    Join Date
    Oct 2008
    Location
    Greater Hyderabad
    Posts
    37
    Rep Power
    0

    Default

    no, i haven't tried with absolute path. i want it to be in my jar, so i want to use its relative path.

    my icon image is in resources folder. i have accessed a text file in the same folder by giving its name directly. so, i have used like this!
    Thanks and Regards,
    Pranav

Similar Threads

  1. setting background color of JFrame form with NetBeans 6.1
    By onefootswill in forum New To Java
    Replies: 4
    Last Post: 08-12-2008, 08:02 AM
  2. Replies: 2
    Last Post: 03-24-2008, 06:29 AM
  3. JFrame problem
    By saytri in forum New To Java
    Replies: 6
    Last Post: 01-11-2008, 06:12 PM
  4. Icon initialization problem
    By saz25 in forum AWT / Swing
    Replies: 1
    Last Post: 12-24-2007, 11:37 PM
  5. Problem Setting offscreen background
    By D34N0 in forum Java Applets
    Replies: 1
    Last Post: 07-14-2007, 12:46 PM

Posting Permissions

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