Click to See Complete Forum and Search --> : setIconImage() problem
I'm sure someone has probably ask this question before, but please bear with
me as I post it again. I am having problems getting an image to display as
the application's icon. I am using the following code to set the image.
setIconImage(Toolkit.getDefaultToolkit().getImage("app_icon.gif"));
I've also tried...
setIconImage((new ImageIcon("app_icon.gif")).getImage());
Both should work, but the icon doesn't show up. The default icon is no
longer there so I at least know something is happening. I am running Win
2000 Professional SP2 and the image is a non-transparent gif 16x16. I would
appreciate any suggestions.
Thanks,
Jeff
Paul Clapham
07-10-2001, 10:50 AM
Probably your GIF file isn't in the current directory, or the current
directory isn't what you think it is. Here's the code I use to do that; it
uses a method that searches the classpath for my icon:
frame.setIconImage(frame.getToolkit().getImage(getClass().getResource("/Bird
icon.jpeg")));
PC2
"Jeff" <jeffdeanda@earthlink.net> wrote in message
news:3b49d0f6$1@news.devx.com...
> I'm sure someone has probably ask this question before, but please bear
with
> me as I post it again. I am having problems getting an image to display as
> the application's icon. I am using the following code to set the image.
>
> setIconImage(Toolkit.getDefaultToolkit().getImage("app_icon.gif"));
>
> I've also tried...
>
> setIconImage((new ImageIcon("app_icon.gif")).getImage());
>
> Both should work, but the icon doesn't show up. The default icon is no
> longer there so I at least know something is happening. I am running Win
> 2000 Professional SP2 and the image is a non-transparent gif 16x16. I
would
> appreciate any suggestions.
>
> Thanks,
> Jeff
>
>
>
Hi Paul,
Thanks for the advice. I figured out what it was. Here's my code now:
setIconImage(new
ImageIcon(getClass().getResource("/app_icon.gif")).getImage());
And what I was using before:
setIconImage((new ImageIcon("app_icon.gif")).getImage());
It seems that by excluding "getClass().getResource("/app_icon.gif")" from
the call it wasn't able to retrieve the graphic.
Thanks,
Jeff
"Paul Clapham" <pclapham@core-mark.com> wrote in message
news:3b4b146a$1@news.devx.com...
> Probably your GIF file isn't in the current directory, or the current
> directory isn't what you think it is. Here's the code I use to do that;
it
> uses a method that searches the classpath for my icon:
>
>
>
frame.setIconImage(frame.getToolkit().getImage(getClass().getResource("/Bird
> icon.jpeg")));
>
> PC2
>
> "Jeff" <jeffdeanda@earthlink.net> wrote in message
> news:3b49d0f6$1@news.devx.com...
> > I'm sure someone has probably ask this question before, but please bear
> with
> > me as I post it again. I am having problems getting an image to display
as
> > the application's icon. I am using the following code to set the image.
> >
> > setIconImage(Toolkit.getDefaultToolkit().getImage("app_icon.gif"));
> >
> > I've also tried...
> >
> > setIconImage((new ImageIcon("app_icon.gif")).getImage());
> >
> > Both should work, but the icon doesn't show up. The default icon is no
> > longer there so I at least know something is happening. I am running Win
> > 2000 Professional SP2 and the image is a non-transparent gif 16x16. I
> would
> > appreciate any suggestions.
> >
> > Thanks,
> > Jeff
> >
> >
> >
>
>
devx.com
Copyright Internet.com Inc. All Rights Reserved