Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

having trouble displaying JFrame after setIconImage

 
Nirvikalp Rao
Greenhorn
Posts: 27
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I started learning swing, and was trying to create and display simple JFrame.
But If I am setting Icon image using
setIconImage()
,the Frame
does not show up.
Here is the code:



But if I remove 16th and 17th line,the Frame gets Displayed.
What am I missing??
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code works fine with me, I can't see a problem (besides the fact that you are using show() method which is deprecated).
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Most probably your img reference is null.
Run your code from the command line and copy paste your stack trace here.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even when the img is null an exception won't be thrown.
 
Nirvikalp Rao
Greenhorn
Posts: 27
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:
Most probably your img reference is null.
Run your code from the command line and copy paste your stack trace here.


Sorry for late response.
It is not causing any exception,so there is no trace, as i said earlier program compiles and runs fine.
The problem is, the newly created window does not appear,as if I am using setVisible(false).
Which is not the case.
My package structure is "com.swing.mine". I have kept "icon.gif" in the directory which contains
"com".I tried putting image in "com.swing.mine" too, neither worked.
 
Nirvikalp Rao
Greenhorn
Posts: 27
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kemal Sokolovic wrote:Even when the img is null an exception won't be thrown.


Hey Kemal, I called "img.toString()" and it printed
sun.awt.image.ToolkitImage@1595f51
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a JPG or PNG image instead of GIF.
 
Nirvikalp Rao
Greenhorn
Posts: 27
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Use a JPG or PNG image instead of GIF.

That worked,
However I am wondering,Is there no support for GIF's.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://bugs.sun.com/view_bug.do?bug_id=6274394 --- unresolved
http://bugs.sun.com/view_bug.do?bug_id=4088017 -- won't fix

More if you search Google for bug "gif" setIconImage site:bugs.sun.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic