Results 1 to 11 of 11
- 10-21-2009, 08:43 AM #1
Member
- Join Date
- Oct 2009
- Posts
- 29
- Rep Power
- 0
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)
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)
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); }
Java Code:Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif");
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..
- 10-21-2009, 09:26 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 14
So add the image to the jar file when you create the jar file.
- 10-21-2009, 02:48 PM #3
Member
- Join Date
- Oct 2009
- Posts
- 29
- Rep Power
- 0
- 10-21-2009, 03:07 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 14
Read the API specs for Class.getResource to find out the rules of how to locate the file within the jar file.
- 10-21-2009, 03:14 PM #5
Member
- Join Date
- Oct 2009
- Posts
- 29
- Rep Power
- 0
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"));
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.
- 10-21-2009, 03:27 PM #6
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 14
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.
- 10-21-2009, 03:45 PM #7
Member
- Join Date
- Oct 2009
- Posts
- 29
- Rep Power
- 0
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..
- 10-21-2009, 03:54 PM #8
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 14
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.
- 10-21-2009, 03:59 PM #9
Member
- Join Date
- Oct 2009
- Posts
- 29
- Rep Power
- 0
- 10-21-2009, 04:03 PM #10
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 14
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').
- 10-21-2009, 04:13 PM #11
Member
- Join Date
- Oct 2009
- Posts
- 29
- Rep Power
- 0
Similar Threads
-
Can´t change selected/pressed Icon of a JMenu
By Valhallon in forum AWT / SwingReplies: 3Last Post: 07-08-2011, 10:16 PM -
How to change Window Icon
By sharafat in forum AWT / SwingReplies: 7Last Post: 01-15-2010, 12:37 AM -
to change the destination folder
By raghu9198 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 02-23-2009, 08:45 AM -
Problem in setting icon for JFrame!
By pranav13 in forum AWT / SwingReplies: 8Last Post: 11-04-2008, 05:24 AM -
Icon initialization problem
By saz25 in forum AWT / SwingReplies: 1Last Post: 12-24-2007, 10:37 PM
Bookmarks