• Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding an image to a JPanel  RSS feed

 
Craig Snowbarger
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to dynamically add an image to a JPanel with this code, but the compiler won't allow me to "add" and image. Is there a simple "setXXX" method for adding images?

 
Fred Hosch
Author
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'd create a JPanel with paintComponent overridden to
draw the image --
public void paintComponent (Graphics g) {
super.paintComponent(g);
g.drawImage(image,0,0,this);
}
and add the JPanel. But there's probably an easier way.
 
Craig Snowbarger
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your input, Fred. I ended up attaching my image as an Icon on an empty JLabel within my JPanel. Works great!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!