Results 1 to 9 of 9
- 10-23-2008, 06:30 AM #1
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
- 10-24-2008, 04:30 AM #2
Member
- Join Date
- Oct 2008
- Posts
- 2
- Rep Power
- 0
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.
- 10-24-2008, 06:05 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 10-24-2008, 09:55 AM #4
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
- 10-24-2008, 10:37 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 11-03-2008, 10:27 AM #6
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
- 11-03-2008, 10:38 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you try it with an absolute path?
- 11-03-2008, 02:33 PM #8
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?
- 11-04-2008, 05:24 AM #9
Similar Threads
-
setting background color of JFrame form with NetBeans 6.1
By onefootswill in forum New To JavaReplies: 4Last Post: 08-12-2008, 07:02 AM -
GUI... setting my background to an image, im using a JFrame
By newtojava7 in forum New To JavaReplies: 2Last Post: 03-24-2008, 05:29 AM -
JFrame problem
By saytri in forum New To JavaReplies: 6Last Post: 01-11-2008, 05:12 PM -
Icon initialization problem
By saz25 in forum AWT / SwingReplies: 1Last Post: 12-24-2007, 10:37 PM -
Problem Setting offscreen background
By D34N0 in forum Java AppletsReplies: 1Last Post: 07-14-2007, 11:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks