Java Swing GUI

How to display an image on JFrame in Java Swing

In this tutorial, we are going to see how to display an image on JFrame in Java Swing. In the following example we have used this image, you can upload it to your project.


Java Program to display an image on JFrame:
import javax.swing.*;

public class ImageJFrame
    JFrame f = new JFrame("Add an image to JFrame");
    ImageIcon icon = new ImageIcon("test.png");
    f.add(new JLabel(icon));
  public static void main(String args[]) 
    new ImageJFrame();


mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *