• Post Reply Bookmark Topic Watch Topic
  • New Topic

Drawing an image in overriding paintComponent  RSS feed

 
M Jay
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm extending JFrame and overriding paintComponent to draw an image, however my image does not appear on the component for some reason, here is the code:



Could anyone help me out and tell me why the image is not being displayed? thanks.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your biggest mistake is igmoring the object passed to paintComponent by
reassigning to g!

Also, I don't think it's a good idea to do I/O in paintComponent - that
method will be called repeatedly. Have you thought of just using JLabel+ImageIcon --
no need to subclass or write a lot of code!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!