Java Swing How to - Create JLabel with Image icon








Question

We would like to know how to create JLabel with Image icon.

Answer

/*  w w w . ja  v a2  s. com*/
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Main {
  public static void main(String[] args) {
    Icon icon = new ImageIcon("yourImage.png");
    JLabel label = new JLabel("Full Name :", icon, JLabel.LEFT);
    
    JOptionPane.showMessageDialog(null, label);
    
  }
}