• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jpeg in a Jpanel

 
Jason Kretzer
Ranch Hand
Posts: 280
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
I need to display a jpeg on a JPanel. I need it as a background, no other components will be on this JPanel. I have tried to set the jpeg as the icon for a JLabel that takes the entire size of JPanel but the dimensions of the jpeg are too small. I need the jpeg to take up the entire JPanel no matter what the screen resolution is set to.
Could someone give the code on how to do this or at least point me in the right direction?
Thanks!!
 
Angela Lamb
Ranch Hand
Posts: 156
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this should work for you:

You can look at the API for Image to see more options for the getScaledInstance method. I used the SCALE_SMOOTH property in this example, but there are other options that use different scaling algorithms.
 
Jason Kretzer
Ranch Hand
Posts: 280
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much. It worked like a charm!

Jason
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic