Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Create a JLabel with an image icon

import java.awt.FlowLayout; import java.awt.HeadlessException; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class Main extends JFrame {   public Main() throws HeadlessException {     setSize(300, 300);     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     setLayout(new FlowLayout(FlowLayout.LEFT));     Icon icon = new ImageIcon("a.png");     JLabel label1 = new JLabel("Full Name :", icon, JLabel.LEFT);     JLabel label2 = new JLabel("Address :", JLabel.LEFT);     label2.setIcon(new ImageIcon("b.png"));     getContentPane().add(label1);     getContentPane().add(label2);   }   public static void main(String[] args) {     new Main().setVisible(true);   } }