Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-13-2008, 07:56 PM
Member
 
Join Date: Jan 2008
Location: Dhaka, Bangladesh
Posts: 5
sharafat is on a distinguished road
How to change Window Icon
Can anybody please give an example code on how to change the icon in the upper-left corner of a window?
Using setImageIcon() doesn't seem to work.
If it can be changed through a property in NetBeans IDE, then how's that supposed to do?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-13-2008, 10:49 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
In the Netbeans properties window for your form, try iconImage. Otherwise, try:
Code:
Image icon = Toolkit.getDefaultToolkit().getImage("icon.gif"); frame.setIconImage(icon);
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-14-2008, 09:03 AM
Member
 
Join Date: Jan 2008
Location: Dhaka, Bangladesh
Posts: 5
sharafat is on a distinguished road
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:

Code:
public frame() { Image icon = Toolkit.getDefaultToolkit().getImage("abc.jpg"); JFrame frame2 = new JFrame("Hi"); frame2.setIconImage(icon); frame2.setVisible(true); initComponents(); }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-14-2008, 03:58 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-14-2008, 09:12 PM
Member
 
Join Date: Jan 2008
Location: Dhaka, Bangladesh
Posts: 5
sharafat is on a distinguished road
Well, finally managed to display the icon image. The final piece of code needed was:

Code:
FrameName.setIconImage(Toolkit.getDefaultToolkit().getImage("abc.jpg"));
And the image must be placed in the project root directory - in this case,
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?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 02-10-2008, 05:11 AM
Member
 
Join Date: Feb 2008
Posts: 1
qeuin is on a distinguished road
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:
Code:
setIconImage(Toolkit.getDefaultToolkit().getImage( MainJFrame.class.getResource("imgs/video.jpg")));
This is an example when I have file video.jpg in folder imgs and changing image in a window of class MainJFrame.

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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 02-10-2008, 07:13 AM
Member
 
Join Date: Jan 2008
Location: Dhaka, Bangladesh
Posts: 5
sharafat is on a distinguished road
Many many thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Icon initialization problem saz25 AWT / Swing 1 12-24-2007 11:37 PM
Changing icon of JOptionPane mew New To Java 3 12-21-2007 08:01 AM
How to set an Icon in a Label? Soda New To Java 2 12-07-2007 01:38 PM
How can I add an ICON on a JDialog's Title-Bar? iimasd AWT / Swing 2 11-06-2007 01:54 PM
To add an icon to my project Albert AWT / Swing 1 07-13-2007 04:14 PM


All times are GMT +3. The time now is 01:09 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org