CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Swing > Display Image in Java Swing Application

Swing Tutorial

  • What Is Java Swing
  • First Program
  • What is AWT
  • Advantages of Swing Over AWT
  • JFrame
  • Swing Components
  • JLabel
  • JTextField
  • JPasswordField
  • JButton
  • Event Handling
  • FlowLayout
  • BorderLayout
  • GridLayout
  • GridBagLayout
  • BoxLayout
  • JPanel
  • JCheckBox
  • JRadioButton
  • Border Component
  • JComboBox
  • JList
  • JList with MVC
  • Mouse Event
  • Key Event
  • JMenuBar
  • JTextArea
  • Using Color
  • Use Font
  • Display Image/Icon
  • Dialog Box
  • JTable
  • JDesktopPane and JInternalFrame
  • JDesktopPane
  • JInternalFrame
  • Adapter Classes
  • Swing Timer
  • JScrollPane
  • JSlider
  • JProgressBar
  • JSeparator
  • JToolBar
  • ActionListener
  • ItemListener
  • Worker Thread
  • Nimbus Look and Feel

Display Image in Java Swing Application

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 · 1 min read · 0 Comments
Share: in X

To display an image in a Java Swing application, we can use the JLabel component to hold the image and add it to a container, such as a JFrame or JPanel. In this article, we will learn to display image in Java Swing Application.

Table of Contents

  • 1. Create JLabel Component
  • 2. Add JLabel to Container
  • 3. Set JLabel Size
  • 4. Make Container Visible
  • 5. Complete Example Code
  • 6. Output

1. Create JLabel Component

Create a new JLabel object and load the image file using the ImageIcon class.

    JLabel imageLabel = new JLabel(new ImageIcon("path/to/image.png"));

    2. Add JLabel to Container

    Add the JLabel component to a container such as a JFrame or JPanel.

      JFrame frame = new JFrame("My Application");
      frame.getContentPane().add(imageLabel);

      3. Set JLabel Size

      Set the size and position of the JLabel within the container.

        imageLabel.setBounds(0, 0, 200, 200);

        4. Make Container Visible

        Make the container visible.

          frame.setVisible(true);

          5. Complete Example Code

          Following is an example code that displays the image in a JFrame.

          import javax.swing.ImageIcon;
          import javax.swing.JFrame;
          import javax.swing.JLabel;
          
          public class ImageDemo {
          	public static void main(String[] args) {
          		JFrame frame = new JFrame("Image Display Example");
          		frame.setSize(700, 500);
          
          		JLabel imageLabel = new JLabel(new ImageIcon("C:\\Users\\codersathi\\Downloads\\LogoWithText.png"));
          		imageLabel.setBounds(0, 0, 400, 400);
          		frame.add(imageLabel);
          
          		frame.setVisible(true);
          	}
          }

          6. Output

          The output of the above code is:

          Display image in Java Swing

          Related Posts:

          • Load Balancing
          • What Is Java Swing? A Complete Guide to Java’s GUI Toolkit
          • Control Statements in Java
          • MySQL Commands for Developers
          • Internationalization in Java
          • Install and Set Up Java Development Environment
          Tags:javaswing
          Was this article helpful?
          ← Previous ArticleUse Font in Java Swing Application
          Next Article →Declaration in Java

          Recent Posts

          • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
          • How to Use AWS CloudFront Signed URLs in Spring Boot?
          • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
          • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
          • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
          CoderSathi

          Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

          Linkedin

          Quick Links

          • About
          • Contact

          Popular Topics

          • Java
          • Spring Boot
          • AWS
          • DevOps
          • MongoDB
          • Linux
          • Git
          • How to
          © 2026 CoderSathi. All rights reserved. Privacy Policy · Sitemap