Results 1 to 8 of 8
Thread: How to change Window Icon
- 01-13-2008, 06:56 PM #1
Member
- Join Date
- Jan 2008
- Location
- Dhaka, Bangladesh
- Posts
- 5
- Rep Power
- 0
- 01-13-2008, 09:49 PM #2
In the Netbeans properties window for your form, try iconImage. Otherwise, try:
Java Code:Image icon = Toolkit.getDefaultToolkit().getImage([COLOR=#0066ff][I]"icon.gif"[/I][/COLOR]); frame.setIconImage(icon);
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 01-14-2008, 08:03 AM #3
Member
- Join Date
- Jan 2008
- Location
- Dhaka, Bangladesh
- Posts
- 5
- Rep Power
- 0
Umm... still not working. Probably the image path isn't correct. My project name is "Test", java file (class) name is frame.java . I placed an image file named abc.jpg . The project directory structure is as below:
Test -> src -> frame.java, frame.form, abc.jpg
-> build -> classes -> frame.class
Is the following code correct:
Java Code:public frame() { Image icon = Toolkit.getDefaultToolkit().[B]getImage("[COLOR="Red"]abc.jpg[/COLOR]")[/B]; JFrame frame2 = new JFrame("Hi"); frame2.setIconImage(icon); frame2.setVisible(true); initComponents(); }
- 01-14-2008, 02:58 PM #4
Since it is isn't much, post you entire .java source file containing this code - what you have there doesn't look wrong, but I'm not sure why you made a frame constructor. Your path doesn't look correct, which is likely causing your problem - have you experimented putting the .jpg in other locations? How about within build/classes where your class is located? Isn't this where a java program is run, by using classes, right? So wouldn't it make sense to put the .jpg in the classes folder? I dunno, you tell me.
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 01-14-2008, 08:12 PM #5
Member
- Join Date
- Jan 2008
- Location
- Dhaka, Bangladesh
- Posts
- 5
- Rep Power
- 0
Well, finally managed to display the icon image. The final piece of code needed was:
And the image must be placed in the project root directory - in this case,Java Code:[I]FrameName[/I].setIconImage(Toolkit.getDefaultToolkit().getImage("abc.jpg"));
Test -> abc.jpg
But the problem is, the JAR file produced by NetBeans 6 doesn't include that image file and hence showing the default coffee-cup icon instead. I added the image file in the JAR file, but nothing changed. When running from the NetBeans IDE, it's showing just fine, but from the Binary file the IDE produces, it is not. Any idea?
- 02-10-2008, 04:11 AM #6
Member
- Join Date
- Feb 2008
- Posts
- 1
- Rep Power
- 0
Put the image in the folder where you have the form's sourcecode which is using this image or in a subfolder. (Then it should be included in JAR automatically)
Then load the image using:
This is an example when I have file video.jpg in folder imgs and changing image in a window of class MainJFrame.Java Code:setIconImage(Toolkit.getDefaultToolkit().getImage( MainJFrame.class.getResource("imgs/video.jpg")));
You can set this directly in NetBeans properties. You have to open window of iconImage property and then choose to "set property using "custom code"".
There's no difference, but it looks nicer, because then you have your code in the NetBeans generated code.
Hope this would work
- 02-10-2008, 06:13 AM #7
Member
- Join Date
- Jan 2008
- Location
- Dhaka, Bangladesh
- Posts
- 5
- Rep Power
- 0
Many many thanks. :)
- 01-15-2010, 12:37 AM #8
Member
- Join Date
- Jan 2010
- Posts
- 1
- Rep Power
- 0
What about web start?
I am able to get the icon to change in a regular java application by following these instructions. I have a folder "Images" in the "src" directory and everything works for the java application as is.
However...when I switch the application to enable java web start, I am able to build the application as usual, but when I go to run the application I get an error. I can toggle back and forth between "<default config"> and "Web Start" in the drop down menu on the main netbeans page (just to the left of the build hammer) and the app correspondingly works/doesn't work. In the "web start" mode, the error is clearly related to the image.
So...do I have to copy that Image directory somwhere where the web start application can find/use it?
Similar Threads
-
Icon initialization problem
By saz25 in forum AWT / SwingReplies: 1Last Post: 12-24-2007, 10:37 PM -
Changing icon of JOptionPane
By mew in forum New To JavaReplies: 3Last Post: 12-21-2007, 07:01 AM -
How to set an Icon in a Label?
By Soda in forum New To JavaReplies: 2Last Post: 12-07-2007, 12:38 PM -
How can I add an ICON on a JDialog's Title-Bar?
By iimasd in forum AWT / SwingReplies: 2Last Post: 11-06-2007, 12:54 PM -
To add an icon to my project
By Albert in forum AWT / SwingReplies: 1Last Post: 07-13-2007, 03:14 PM


LinkBack URL
About LinkBacks

Bookmarks