File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes jpeg in a Jpanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jpeg in a Jpanel" Watch "jpeg in a Jpanel" New topic

jpeg in a Jpanel

Jason Kretzer
Ranch Hand

Joined: May 31, 2001
Posts: 280
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?

Jason R. Kretzer<br />Software Engineer<br />System Administrator<br /><a href="" target="_blank" rel="nofollow"></a>
Angela Lamb
Ranch Hand

Joined: Feb 22, 2001
Posts: 156
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

Joined: May 31, 2001
Posts: 280
Thank you very much. It worked like a charm!

I agree. Here's the link:
subject: jpeg in a Jpanel
It's not a secret anymore!