Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with setIconImage  RSS feed

 
Steve Vittoria
Ranch Hand
Posts: 35
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

I'm trying to replace the default Java cup icon with another icon, but it doesn't seem to be working quite right. The Java cup icon is gone, but my icon is not being displayed, it's blank.

Here's three different ways that I've tried this...







All three ways produced the same thing, which is to say a blank icon. I even tried converting my icon into a GIF, but still the same.

This is my directory structure where the DVD.ico file is located...

C:\My Projects\Movie Theater\src\movietheater\images\

My java file is located at...

C:\My Projects\Movie Theater\src\movietheater\

I've tried putting the icon on the root of drive C and then used "DVD.ico", but that too did not work.

This is most likely a very simple thing, but I can't seem to get it working. Any clues as to what is wrong?

Thanks!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yuo may find .ico files are not supported in java

try using a .gif file (e.g. windows save.gif or open.gif)
setIconImage(new ImageIcon("test.gif").getImage());
 
Steve Vittoria
Ranch Hand
Posts: 35
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Michael, thanks for the reply.

I did try using a gif file, but that too did not work.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the line I posted does work, provided you extend JFrame
if you're constructing one, it is
frame.setIconImage(new ImageIcon("test.gif").getImage());

put your .gif file into the same folder as your java file,
and it should work from there.

if it does, then you can try subfolders for your .gifs,
and/or testing with .ico files
 
Steve Vittoria
Ranch Hand
Posts: 35
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
frame.setIconImage(new ImageIcon("test.gif").getImage());

put your .gif file into the same folder as your java file,
and it should work from there.

if it does, then you can try subfolders for your .gifs,
and/or testing with .ico files


I've tried those suggestions, but still not working.

So the problem must be that I'm not extending JFrame. But when I try doing that I get an error stating that I'm missing a '{'.

Here is a snippet of my code...



[ May 14, 2006: Message edited by: Steve Vittoria ]
[ May 14, 2006: Message edited by: Steve Vittoria ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I stripped all the non-related stuff, and this worked OK for me
(change the name to your.gif file)




> public class MovieTheater extends JFrame, JPanel
java doesn't support multiple inheritance
 
Suman Mummaneni
Ranch Hand
Posts: 96
Android Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Just try this and tell me if it works
Declare this as a constance varivale.
private static final Image APP_ICON=Toolkit.getDefaultToolkit().getImage(
CliperOptions.class.getResource("alarms.gif"));

in your Constructor.
call the setIconImage("APP_ICON);

be sure that your APP_ICON max size must be of 24x24 pixel.

 
Steve Vittoria
Ranch Hand
Posts: 35
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It finally worked when I put the GIF file in the following directory...

C:\My Projects\Movie Theater\

BTW, does Java not support GIFs or PNGs with transparency? My GIF file has white setup as the transparent color, but it's still being displayed in my program with the white area. The same thing happens with a PNG file.


Originally posted by Suman Mummaneni:
Declare this as a constance varivale.
private static final Image APP_ICON=Toolkit.getDefaultToolkit().getImage(
CliperOptions.class.getResource("alarms.gif"));

in your Constructor.
call the setIconImage("APP_ICON);


I get an error with this stating that it cannot find symbol symbol : class CliperOptions.

Thanks for all your help guys!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!