Java Basic Problems

Java: How to show image in JLabel

How to show image on JLabel:

If we need to show image as a background of a JLabel, then we can easily show it by using ImageIcon and then by setting that  ImageIcon to the JLabel.

Download this project from:

I have uploaded the project  and I used  NetBeans IDE 5.0 (You can use latest version) and JDK 1.4.2

I am not giving the whole code here, just I am mentioning the Core Portion of the code. Better you download the project and Run it in your computer.


import javax.swing.*;

import java.awt.image.BufferedImage;

public class jLabelImgIcon extends javax.swing.JFrame {

private void myInit()


 ImageIcon icon = new ImageIcon(“C:\\myworkspace\\sample.png”);

 icon = new ImageIcon(icon.getImage().getScaledInstance(100, 100, BufferedImage.SCALE_SMOOTH));







In the output Image is viewing on JLabel  using ImageIcon and jLabel1.setIcon.

JLabel Image Icon

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s