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 display image in 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 "display image in jpanel" Watch "display image in jpanel" New topic

display image in jpanel

Dan Longest

Joined: Apr 28, 2005
Posts: 5
I want to display an image using swing. How do I add the image to a jpanel or jframe? I've tried finding a way to do it with Image and ImageIcon with no success. A link to the right information would be fine.


"If I want a group decision I'll look in a mirror" - Warren Buffett
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
here's a post from a couple of days ago, with a link to the FAQ on this,
also with query re missing call - include the line
as the first line in paintComponent()

perhaps you just need to use a JLabel, which takes an icon as a parameter
[ August 14, 2005: Message edited by: Michael Dunn ]
Russell Ray
Ranch Hand

Joined: Apr 25, 2005
Posts: 116
First of all, I am am very new in using Swing components and I am learning under fire. You recommedation works for 1.4 JDK. Is there a different way for JDK 1.3? I am having a similar problem with the same subject, but in JDK 1.3. I do not have the ImageIO class available to me. My problem is simple, the images are not displaying.

Thanks for any suggestions.

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
they display OK for me, java 1.4.0_01
I agree. Here's the link:
subject: display image in jpanel
It's not a secret anymore!