Java Swing Program to demonstrate JLabel with Icon
Program
import javax.swing.*;
public class JLabelIconDemo
{
public static void main(String args[])
{
JFrame frm = new JFrame("JLabel Demo");
JLabel lblUserName, lblPassword;
ImageIcon icoUserName, icoPassword;
icoUserName = new ImageIcon("username.png");
lblUserName = new JLabel(icoUserName);
lblUserName.setBounds(0, 0, 100, 50);
icoPassword = new ImageIcon("password.png");
lblPassword = new JLabel(icoPassword);
lblPassword.setBounds(0, 50, 100, 50);
frm.add(lblUserName);
frm.add(lblPassword);
frm.setSize(300, 300);
frm.setLayout(null);
frm.setVisible(true);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Output