Results 1 to 9 of 9
- 10-23-2008, 06:30 AM #1
Problem in setting icon for JFrame!
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(Step1.class.getResource("myicon.jpg" )));
InputStream imgStream = this.getClass().getResourceAsStream("myicon.jpg");
BufferedImage bi = ImageIO.read(imgStream);
ImageIcon myImg = new ImageIcon(bi);
Thanks in advance!Thanks and Regards,
- 10-24-2008, 04:30 AM #2Member
- Join Date
- Oct 2008
- Rep Power
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
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,
- 10-24-2008, 10:37 AM #5
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,
- 11-03-2008, 10:38 AM #7
- 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
- By onefootswill in forum New To JavaReplies: 4Last Post: 08-12-2008, 07:02 AM
- By newtojava7 in forum New To JavaReplies: 2Last Post: 03-24-2008, 05:29 AM
- By saytri in forum New To JavaReplies: 6Last Post: 01-11-2008, 05:12 PM
- By saz25 in forum AWT / SwingReplies: 1Last Post: 12-24-2007, 10:37 PM
- By D34N0 in forum Java AppletsReplies: 1Last Post: 07-14-2007, 11:46 AM