Results 1 to 11 of 11
  1. #1
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default Icon change and lib folder problem

    Hi.. I'm new to java, just made my first java desktop program several days ago.
    I have two problems, hope you can help.

    1. I've read about changing the java icon here
    java-forums.org/new-java/21799-images-jar-file-via-eclipse.html
    java-forums.org/new-java/21920-netbeans-6-5-java-icons-differences.html
    java.sun.com/docs/books/tutorial/uiswing/components/icon.html
    java.sun.com/javase/6/docs/api/javax/swing/ImageIcon.html#getImage%28%29
    devx.com/tips/Tip/5697

    I got the following errors with this trick java-forums.org/java-2d/18166-changing-java-icon-2.html
    Java Code:
    java.lang.IllegalArgumentException: input == null!
            at javax.imageio.ImageIO.read(ImageIO.java:1362)
            at binergabung.BinergabungView.<init>(BinergabungView.java:44)
            at binergabung.BinergabungApp.startup(BinergabungApp.java:19)
            at org.jdesktop.application.Application$1.run(Application.java:171)
    with this trick I got the following errors java-forums.org/awt-swing/5373-how-change-window-icon.html
    Java Code:
    Uncaught error fetching image:
    java.lang.NullPointerException
            at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:99)
            at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:113)
            at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:240)
            at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
            at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
    I'm using netbeans 6.7.1, I'm changing the frame properties at the constructor. Here's my code

    Java Code:
    /*
     * BinergabungView.java
     */
    
    package binergabung;
    
    import java.awt.Color;
    import org.jdesktop.application.Action;
    import org.jdesktop.application.SingleFrameApplication;
    import org.jdesktop.application.FrameView;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import java.io.FileNotFoundException;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.DataInputStream;
    import java.io.IOException;
    import java.io.File;
    
    import java.awt.Toolkit;
    import java.awt.Image;
    import java.awt.Cursor;
    
    /**
     * The application's main frame.
     */
    public class BinergabungView extends FrameView {
    
        public BinergabungView(SingleFrameApplication app) {
            super(app);
            initComponents();      
            
            //Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
            Image icon = Toolkit.getDefaultToolkit().getImage(this.getFrame().getClass().getResource("/icon.gif"));
            this.getFrame().setIconImage(icon);
    
            this.getFrame().setResizable(false);
            this.getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
    If I use this code
    Java Code:
    Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
    It's working with that code but I have to put the icon in the same folder as the jar, I want it to load the image from the jar not from outside of the jar..


    2. I noticed that in order to make the jar application working I have to put the lib folder(contains appframework-1.0.3.jar and swing-worker-1.1.jar) with the same directory of the jar file. After doing some search I know that it's framework to make the jar file working. I want to intergrate it into the jar file, how to do it?

    As I've stated above, I'm using netbeans 6.7.1.

    I have one problem again, but I don't know if I can post it here or make new topic.

    Hope you can help.. Thanks..

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    So add the image to the jar file when you create the jar file.

  3. #3
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    So add the image to the jar file when you create the jar file.
    The image is already in the jar file..
    Last edited by LeonLanford; 10-21-2009 at 02:53 PM.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Read the API specs for Class.getResource to find out the rules of how to locate the file within the jar file.

  5. #5
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Read the API specs for Class.getResource to find out the rules of how to locate the file within the jar file.
    I already read it many times, I also already read others' example code from above links as well, I'm pretty sure this is the right way to call for it, the netbeans autocomplete function also show no errors as well.

    Java Code:
    Image icon = Toolkit.getDefaultToolkit().getImage(this.getFrame().getClass().getResource("/icon.gif"));
    There's no build errors but when I run it I encountered errors :(

    I though I need to make the code in the scope of 'try' but it still won't work :(
    Java Code:
            try
            {
                Image icon = Toolkit.getDefaultToolkit().getImage(this.getFrame().getClass().getResource("/icon.gif"));
                this.getFrame().setIconImage(icon);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
    Last edited by LeonLanford; 10-21-2009 at 03:16 PM.

  6. #6
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Huh? If you read my post above again you will see that there is something specific that I asked you to read about the specs.

    I never said you have compile time or run time errors.

  7. #7
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default

    Just did trial and errors, and I found out that I have to get rid of getFrame()
    Thanks for the help :)

    I still don't know how to intergrate the lib folder to the jar file though..

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Do yourself a big favor and don't do trial and error. Read the API specs to find out what works and what doesn't.

  9. #9
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Do yourself a big favor and don't do trial and error. Read the API specs to find out what works and what doesn't.
    I've told you I already read it..
    What I know by reading is I must point the url to the frame itself the get the resource, I did that and not working so I did it with trial and error..

  10. #10
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Did you read the part that says
    Finds a resource with a given name. The rules for searching resources associated with a given class are implemented by the defining class loader of the class. This method delegates to this object's class loader. If this object was loaded by the bootstrap class loader, the method delegates to ClassLoader.getSystemResource.

    Before delegation, an absolute resource name is constructed from the given resource name using this algorithm:

    If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'.
    Otherwise, the absolute name is of the following form:
    modified_package_name/name

    Where the modified_package_name is the package name of this object with '/' substituted for '.' ('\u002e').

  11. #11
    LeonLanford is offline Member
    Join Date
    Oct 2009
    Posts
    29
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Did you read the part that says
    Yes I read that.
    What I think is setIconIamge function is frame's property so I need to get the frame first.

Similar Threads

  1. Can´t change selected/pressed Icon of a JMenu
    By Valhallon in forum AWT / Swing
    Replies: 3
    Last Post: 07-08-2011, 10:16 PM
  2. How to change Window Icon
    By sharafat in forum AWT / Swing
    Replies: 7
    Last Post: 01-15-2010, 12:37 AM
  3. to change the destination folder
    By raghu9198 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-23-2009, 08:45 AM
  4. Problem in setting icon for JFrame!
    By pranav13 in forum AWT / Swing
    Replies: 8
    Last Post: 11-04-2008, 05:24 AM
  5. Icon initialization problem
    By saz25 in forum AWT / Swing
    Replies: 1
    Last Post: 12-24-2007, 10:37 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
  •